Wordpress帖子类别:如何排除孩子?

时间:2012-07-03 08:02:36

标签: wordpress categories children grandchild

我有这样的类别结构...

- Shirts
   - Small
         - Red
         - blue
         - green
   - Medium
   - Large
- Jackets
- Hats

......'衬衫'的ID是1.当我这样做时......

<ul>
<?php 
query_posts('cat=1&showposts=10&order=ASC'); 
if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
<?php endwhile; else: ?>
<?php _e('Nothing Here!'); ?>
<?php endif; ?>
</ul>

......而不是只展示衬衫的孩子,它也展示了孙子。为了说明,屏幕上的输出显示小,红,蓝,绿中,大,而不是小,中,大。

如何排除孙子孙女?

提前致谢。

2 个答案:

答案 0 :(得分:0)

您可以尝试使用category__not_in参数吗?例如

query_posts(array('cat' => 1, 'showposts' => 10, 'order' => 'ASC', 'category__not_in' => array(grandchildren_ids)));

答案 1 :(得分:0)

为查询添加深度:

<?php query_posts('cat=1&showposts=10&order=ASC&depth=1'); ?>
相关问题