Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Can you post some of your code? It will help get to the answer –  Mridul Aggarwal Jan 29 '13 at 11:11
    
@MridulAggarwal his code doesn't matter, he has asked general question –  Eugene Manuilov Jan 29 '13 at 11:55
    
Then i understood it wrong. My Bad –  Mridul Aggarwal Jan 29 '13 at 12:26
add comment

1 Answer 1

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 );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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