• 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)

    1. open wp-includes/classes.php
    2. 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 145

    128-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;
    }

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thanks for updating us on this.. 😉 I’m sure others that happen to have the same problem as you had, might learn from this then. 😉

    spencerp

    Thanks, this was just what I needed =)
    And this should be the default behaviour of WordPress, IMHO.

    Glad to hear that this one was useful Chionsas.. 😉 =)

    spencerp

    In WP 2.1.2, comment out line 844 in wp-includes/query.php:

    $whichcat .= get_category_children($q['cat'], '', ', ');

    Is there really no way of doing this without hacking?

    I commented out line 844 in WP 2.1.2, and parent categories are still showing child categories’ posts. Is there anything else that needs to be changed to get this to work in 2.1.2…? Thanks!

    atomictoyguy

    (@atomictoyguy)

    Same result as CatrionaC here. I would really like to get this working but I can’t figure it out for the life of me.

    Thread Starter Amāvāsyā Cowboy

    (@tikimaticdotcom)

    just working on wp 2.2 – the hack is dead!!! Hell & fury !!!! AAArrrh !!! stay tuned – gotta find a way

    Thread Starter Amāvāsyā Cowboy

    (@tikimaticdotcom)

    i’m in as hurry – so the solution for the moment is ti use WP 2.0.10 🙁

    I think I’ve got it for 2.1.3:

    In wp-includes/query.php, modify lines 792-794, truncating lines 792 and 794 as follows (be sure to add the semi-colon on the new end of the line):

    $in_cats .= "$cat, ";
    else
    $out_cats .= "$cat, ";

    Remove
    $whichcat .= get_category_children($q[‘cat’], ”, ‘, ‘);
    from line: 842
    In: wp-includes/query.php

    This is how I did it. Works perfect.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Howto : not display child categories’ posts in parent category archive’ is closed to new replies.