我有一个父类别和几个子类别。我也有几个属于儿童类别的帖子。每个帖子可以分为几个类别。我想知道如何查询post表,这样当我想显示父类别中的所有帖子时,我将获得子类别下的所有帖子。结果必须是唯一的帖子。对不起,我的英语不好。
这是我的代码:
$cats = get_categories(\'child_of=95\');
// 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 ?>
<h2><?php the_title(); ?></h2>
<a href="<?php the_permalink();?>"><?php the_content(); ?></a>
<?php echo \'<hr/>\'; ?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
但我总是收到重复的帖子。