2017-02-16 6 views
0

にカテゴリIDを取得し、私はcategory.phpでこのコードを持っていると私は私がしたカテゴリ、「$cat」と私は何かを書きましたが、仕事をしたくはありませんid 63と呼ばカテゴリからの投稿を表示します:/WordPressの配列

<?php 
$cat->term_id; 
$my_query_args = array(
    'posts_per_page' => 6, 
    'tax_query' => array(
     array(
      'taxonomy' => 'category', 
      'field' => 'id', 
      'terms' => array(63, $cat), 
      'operator' => 'AND' 
     ) 
    ) 
); 
$my_query = new WP_Query($my_query_args); 
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); 

     ?> 
     <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
    <?php 
    endwhile; 
endif; 
wp_reset_postdata(); 

?> 

誰かがなぜ$catに現在表示されているカテゴリは発生しません教えてもらえますか?

ご協力いただきありがとうございます。

答えて

0

おそらく$cat変数はオブジェクトです。 'terms' => array(63, $cat->ID),または'terms' => array(63, $cat->id),

1
$category = get_category(get_query_var('cat')); 
echo $cat_id = $category->cat_ID; 

'terms' => array(63, $cat),を変更しようこれはあなたの現在のカテゴリIDを提供します。あなたはいけないthatsの正常なカテゴリがあまりにも多くの引数を持つことは複雑なようにしたい場合は は今category.php

query_posts('cat='.$cat_id); 

にwordpressのループの開始前に、以下のクエリを配置します。これは、現在のカテゴリIDを確認することで動的に動作します。

1

あなたのtac_queryに 'field'引数を混乱させるかもしれません。

'field' => 'term_id', 

フィールド - 分類法用語をで選択します。可能な値は 'term_id'、 'name'、 'slug'または 'term_taxonomy_id'です。デフォルト値は 'term_id'です。

0

これは= ..

<?php 
$catquery = new WP_Query('cat=3&posts_per_page=10'); 
while($catquery->have_posts()) : $catquery->the_post(); 
?> 
<ul> 
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> 

<ul><li><?php the_content(); ?></li> 
</ul> 
</li> 
</ul> 
<?php endwhile; ?> 
猫にあなたの猫のIDまたは名前を設定してみてください
関連する問題