• This is so basic it cannot really be called a hack, and it may be someone has already pointed it out though I don’t think so. Some people, including myself, have wanted to prevent subcateory posts appearing in the parent category listing. I messed with this for hours yesterday before finding this. It works for me, I cannot say it is fully tested.
    Go to around line 265 in wp_blog_header.php, find the following lines and put /* the code snippet below */ around it.
    $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
    for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
    $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
    $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
    }

    That?¢??s it, no more subcategory posts appearing in the main category post listing. You can see it in action in my journal.
    https://www.andrew-hall-artist.com/journal/
    Andrew

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter andrew_h

    (@andrew_h)

    hmmm I know I didn’t come up with such an original version of that’s lol.
    Andrew

    How would this work with the latest nightly build of wordpress? I can’t find that code in wp-blog-header.php

    Hi GuruXL – I am not using nightlys so I don’t know but my guess is that if you search for the function get_category_children you will find the right spot.
    Andrew Hall

    I tried this in WP1.2 (mingus) to no avail. What version of WP are you using that it works?
    Kevin

    I would like to be able to do this also. I have found the lines above, but where is /* the code snippet below */ as indicated in the post, with which to replace them?
    Joan

    Oh, I get it now! I found the original post on Andrew’s site – which explained it a bit better for the not-so-PHP-savvy people like me. What he is saying is comment out that section of code. Works fine for me in WP 1.2. Thanks Andrew!
    Joan

    Hmmm.
    + I know PHP
    + This post fits my wishes perfectly (almost)
    + I know how to remove lines or do remarks
    – I removed the lines, have the latest version 1.2 but still my subcategory posts are shown ??
    I also inserted a echo “test”; to see if I am at the right point of code but nothing was echoed out !?
    What can be the problem?

    I replied to this under “Don’t Show Posts of Children Categories” and got a happy response so I’m posting this here as well. ?? Check out, again, https://www.andrew-hall-artist.com/journal/index.php?p=69 but read my (Minna) comment below it. That’s how I got the thing working
    — Minna

    If you are using nice URIs you also have to comment out $whichcat .= get_category_children($cat, " OR category_id = "); under the // Category stuff for nice URIs part

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘No Subcategory Posts in Parent hack’ is closed to new replies.