2

I have a category structure like following:

A
->B
  ->C
D

(B is sub category of A and C is sub category of B)

I have content only for category "C" and if I open Category "B" the content of category "C" is displayed. How can I prevent this? I want to display "No Posts" if I open Category "B".

3
  • Can you post some of your code? It will help get to the answer Commented Jan 29, 2013 at 11:11
  • @MridulAggarwal his code doesn't matter, he has asked general question Commented Jan 29, 2013 at 11:55
  • Then i understood it wrong. My Bad Commented Jan 29, 2013 at 12:26

1 Answer 1

0

Assuming the context here is filtering out posts from category C when viewing the category B posts archive, you could accomplish this by using the query_posts keyword category__in (which does not include posts from child categories) instead of cat (which does include posts from child categories). Just add it in archive.php or category.php depending on what's appropriate for you theme.

global $wp_query;
$args = array_merge( $wp_query->query, array(
    'category__in' => get_query_var('cat')
));
query_posts( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.