Php Wordpress列出根据给定类别的标签分组的所有帖子
我有一个循环,用于将给定标记的所有帖子按类别分组(请参见下面的代码)。我需要把它转过来,做完全相同的事情,但通过标签为一个给定的类别 在代码示例中,我得到了所有标记为“torrington”的帖子,然后循环显示它们按类别分组,并带有类别的H2(例如“餐厅”) 因此,反过来,我需要将所有项目分类为“餐厅”,然后根据标签对它们进行分组(例如“托林顿”、“丹伯里”等)Php Wordpress列出根据给定类别的标签分组的所有帖子,php,wordpress-theming,wordpress,Php,Wordpress Theming,Wordpress,我有一个循环,用于将给定标记的所有帖子按类别分组(请参见下面的代码)。我需要把它转过来,做完全相同的事情,但通过标签为一个给定的类别 在代码示例中,我得到了所有标记为“torrington”的帖子,然后循环显示它们按类别分组,并带有类别的H2(例如“餐厅”) 因此,反过来,我需要将所有项目分类为“餐厅”,然后根据标签对它们进行分组(例如“托林顿”、“丹伯里”等) 编辑:我已经完成了这一步,但是query_posts语句似乎什么也没有返回: <?php
编辑:我已经完成了这一步,但是query_posts语句似乎什么也没有返回:
<?php
// get all the categories from the database
$tags = get_tags();
// loop through the categries
foreach ($tags as $tag) {
echo($tag->name);
// setup the cateogory ID
$tag_id = $tag->term_id;
echo($tag_id);
// create a custom wordpress query
query_posts("tag_id=$tag_id&cat=eats&post_per_page=100");
// start the wordpress loop!
if (have_posts()) :
echo('posts');
// Make a header for the category
echo '<h2 class="cat-title">'.$tag->name.'</h2>';
while (have_posts()) :
the_post(); ?>
<?php // create our link now that the post is setup ?>
<div class="listing">
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php the_content(); ?>
</div>
<?php //echo '<hr/>'; ?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
明白了。这是对
tag\u id=$tag\u id
的简单更改,而不是tag=$tag\u id
以上代码已更新。相关行为query_posts(“tag_id=$tag_id&cat=eats&post_per_page=100”)代码>
<?php
// get all the categories from the database
$tags = get_tags();
// loop through the categries
foreach ($tags as $tag) {
echo($tag->name);
// setup the cateogory ID
$tag_id = $tag->term_id;
echo($tag_id);
// create a custom wordpress query
query_posts("tag_id=$tag_id&cat=eats&post_per_page=100");
// start the wordpress loop!
if (have_posts()) :
echo('posts');
// Make a header for the category
echo '<h2 class="cat-title">'.$tag->name.'</h2>';
while (have_posts()) :
the_post(); ?>
<?php // create our link now that the post is setup ?>
<div class="listing">
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php the_content(); ?>
</div>
<?php //echo '<hr/>'; ?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>