0
我需要按類別列出帖子,但只限於具有給定標籤(或標籤)的帖子。到目前爲止,我有下面的代碼,它適用於列出按類別分組的所有帖子,但我不確定如何修改它以僅選擇具有給定標籤的帖子。我應該改變什麼?Wordpress按類別列出與標籤匹配的帖子?
<?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 = red&showposts = 100」);' – Steve
如果我的記憶正確地爲我服務,您需要'query_posts(「cat = $ cat_id&tag = red +紅色&showposts = 100" );' –