문제

I have a category structure like this...

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

...where the ID of 'Shirts' is 1. When I do this...

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

... instead of showing just the children of Shirts, it is also showing the grandchildren. To illustrate, the output on the screen is showing Small, red, blue, green Medium and Large ,instead of just Small, Medium and Large.

How can I exclude the grandchildren?

Thanks in advance.

올바른 솔루션이 없습니다

다른 팁

Can you try to use category__not_in parameter? For example

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

Add depth to your query:

<?php query_posts('cat=1&showposts=10&order=ASC&depth=1'); ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top