繁体   English   中英

WordPress按类别列出与标签匹配的帖子?

[英]Wordpress lists posts by category which match a Tag?

我需要按类别列出帖子,但仅针对具有给定标签(或多个标签)的帖子。 到目前为止,我有以下代码,可以很好地列出按类别分组的所有我的帖子,但是我不确定如何修改它以仅选择具有给定标签的帖子。 我应该改变什么?

 <?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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM