我想通過類別頁面上帖子旁邊的標籤顯示相關帖子。 所有相關的帖子我可以找到的代碼片段將用於single.php
的嵌套循環,但我需要它在類別頁面上的循環。用wordpress中的分類模板頁面上的標籤顯示相關帖子
所以,當你去類別「貓」應該輸出如下: 「後1題」,類別「貓」,標籤「小貓」 「相關崗位1.1標題」標籤「小貓」 「相關發佈1.2標題」標籤‘小貓’
‘後2題’,類別‘貓’,標籤‘雄貓’ ‘相關崗位2.1標題’標籤‘雄貓’ ‘相關崗位2.2標題’ ,標籤「tomcats」
...
這是我提出的代碼,但它打破了。
'//第一個查詢 $ my_query = new WP_Query('cat = 6');
// If first query have posts
if($my_query->have_posts()) :
// While first query have posts
while ($my_query->have_posts()) : $my_query->the_post();
?>
<!-- start post -->
<!-- End post div -->
<?php
// tags
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>99,
'caller_get_posts'=>1
);
// Second query
$my_second_query = new WP_Query('$args');
// If second query have posts
if($my_second_query->have_posts()) :
?>
<?php
// While second query have posts
while($my_second_query->have_posts()) : $my_second_query->the_post();
?>
<!-- start post -->
<!-- End post div -->
<?php
// End second while have posts
endwhile;
?>
<?php
// End first while have posts
endwhile;
// End if first query have posts
endif;
?>`
這甚至可能嗎?我無法爲我的生活找到榜樣。 非常感謝提前
謝謝sooo多,我剛從我的假期回來,並將繼續在這個項目上,並與結果回你! –