0

タイトルが示すように、どの投稿がどのカテゴリに属しているかを表示するために投稿をクエリしようとすると、すべての投稿が表示されるだけで、コードまたはループで間違いを犯していないかどうかを確認するために、代わりに fort タグを検索しようとしましたが、これは機能しました

<section class="background-wrapper">
<section class="content">
<div class="heading"><h1>Posts tagged with "coding"..</h1></div>
<div class="module-wrapper">

<?php if (have_posts()): ?>
<?php query_posts('cat=design');//NOTE USING ('tag=css') WORKED ?>

<?php while (have_posts()) : the_post(); ?>
<?php wpb_set_post_views(get_the_ID()); //storing a value of a page view ?>

  <div class="module">
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    <!-- Post Title -->
    <h1 class="post-title">
      <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h1>
    <!-- /Post Title -->

    <?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>

タグを照会する場合、コードを変更する必要がありますか?

4

2 に答える 2

0

使用しているクエリを使用する場合は、クエリに名前ではなくカテゴリ IDquery_posts('cat=###')を指定する必要があります。Id がわからない場合は、次のようなクエリを実行する前に見つけることができます。

$categories = get_the_category(); //gets all the categories
$i=1; 
$name='design'; 
$id='';
while(count($categories) > i){   //Loops through the categories
    if(($categories[$i-1]->cat_name)==$name){ 
        $id=$categories[$i-1]->cat_ID;  //Sets the variable $id to be the id you need
    }
    i++; 
};

$idは、使用していたクエリを実行するために必要なカテゴリ ID である必要があります。

于 2013-07-25T20:24:38.873 に答える