Exclude Post on Sub Category at Top Category

When you on top level category that have sub category, all post on sub category also will be displayed on top category. This make top category and sub category look the same. Separate post from top category and sub category also good for Silo Structure.

To exclude post from sub category you need to edit WordPress file theme that display category page. usually category page using archive.php or index.php depending on your theme.

Place this code before the loop :

<?php  if (is_category()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();

// echo '<h2>Category : '.$cat_obj->name.'</h2>'; uncomment if you want display category name

query_posts(array('category__in' => array($cat_obj->term_id)));

} ?>

You may also like...

1 Response

  1. Juan says:

    Dude you rock tks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *