Question

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.

Pas de solution correcte

Autres conseils

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'); ?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top