Howto : not display child categories’ posts in parent category archive
-
hi i post this ‘cos it’s a way to refresh an old post i found on this forum http://wordpress.org/support/topic/71767
and some of you may be interested…
Well, the goal is that each category displays only its own posts and not those of its child categories.here you go:
(this in WP v.2.0.4, line numbers may change in further versions)- open wp-includes/classes.php
- just insert
//
at the very beginning of these lines – or destroy them:
line 473
$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
line 476
$whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
line 514
$whichcat .= get_category_children($q['cat'], " OR category_id = ");
You’re done! Code is poetry, as they say!
You may then want to do the same with
wp-includes/wp-includes/template-functions-category.php
(the changes below are OPTIONAL)line 201
$query .= get_category_children($hide, " AND cat_ID != ");
And: lines 128-145:
1- insert
/*
at the beginning of line 128
2- insert*/
line 145128-145:
function get_category_children($id, $before = '/', $after = '') {
if ( 0 == $id )
return '';
$cat_ids = get_all_category_ids();
foreach ( $cat_ids as $cat_id ) {
if ( $cat_id == $id)
continue;
$category = get_category($cat_id);
if ( $category->category_parent == $id ) {
$chain .= $before.$category->cat_ID.$after;
$chain .= get_category_children($category->cat_ID, $before, $after);
}
}
return $chain;
}
- The topic ‘Howto : not display child categories’ posts in parent category archive’ is closed to new replies.