0

投稿をカテゴリ別に一覧表示する必要がありますが、特定のタグ (またはタグ) を持つ投稿のみです。これまでのところ、カテゴリ別にグループ化されたすべての投稿を一覧表示するのに問題なく機能する次のコードがありますが、特定のタグを持つ投稿のみを選択するように変更する方法がわかりません。何を変更すればよいですか?

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

1 に答える 1

1

必要なのは、クエリを編集してタグを含めることだけです。 query_posts("cat=$cat_id&tag=tag1+tag1&showposts=100");

すべてが必要であることに注意してくださいtag1+tag1

于 2012-11-25T16:24:22.527 に答える