Php Wordpress按类别列出与标签匹配的帖子?
我需要按类别列出帖子,但只针对具有给定标签的帖子。到目前为止,我有下面的代码,它可以很好地列出我所有按类别分组的帖子,但我不知道如何修改它,以便只选择带有给定标记的帖子。我应该换什么Php Wordpress按类别列出与标签匹配的帖子?,php,wordpress-theming,wordpress,Php,Wordpress Theming,Wordpress,我需要按类别列出帖子,但只针对具有给定标签的帖子。到目前为止,我有下面的代码,它可以很好地列出我所有按类别分组的帖子,但我不知道如何修改它,以便只选择带有给定标记的帖子。我应该换什么 <?php // get all the categories from the database $cats = get_categories(); // loop through the categries
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo "<h2>".$cat->name."</h2>";
// create a custom wordpress query
query_posts("cat=$cat_id&post_per_page=100");
// start the wordpress loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php echo '<hr/>'; ?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
您只需编辑查询以包含标记,即。
query_posts(“cat=$cat_id&tag=tag1+tag1&showposts=100”)代码>
注意:您需要所有的tag1+tag1
您所说的“全部”是什么意思?如果标签是“红色”的,我会不会只做query_posts(“cat=$cat_id&tag=red&showposts=100”)代码>如果我的记忆正确,你需要查询帖子(“cat=$cat\u id&tag=red+red&showposts=100”)代码>