Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress按类别列出与标签匹配的帖子?_Php_Wordpress Theming_Wordpress - Fatal编程技术网

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”)