• For years, I have used a plug-in to hide posts in child categories so that only posts for the current category show.

    This has stopped working after a recent update and my sites now look awful. I haven’t managed to find a replacement plug-in that works (only others that have also recently stopped working).

    It seems to me that this should be core behaviour but at the very least, PLEASE can you consider a ‘Hide Child Posts’ option.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Which plugin were you using?

    The in_category conditional might be a better approach than a plugin:

    https://codex.www.ads-software.com/Template_Tags/in_category

    Thread Starter mystifier

    (@mystifier)

    I have used ‘Kinderlose’ for years (https://guff.szub.net/2007/11/30/kinderlose/)
    This was a simple add_filter(‘posts_where’, ‘kinderlose_where’);

    And ‘Post Category Only’ worked fine (https://www.ads-software.com/extend/plugins/post-category-only/)
    which added a class post_category_only

    Now neither have any effect and I can’t find one that works.

    This is a big failing in wordpress; showing all child category posts on large sites is a crazy idea; being able to hide them as an option at least would be a massive God-sent.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Are you trying to only show posts from the parent category in an archive type page or are you trying to list all the parent categories?

    Thread Starter mystifier

    (@mystifier)

    When a category is selected, I only want posts to show for that category… not also posts for every single child (sub)category.

    I have exhausted plug-ins so a hack would be greatly appreciated.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Easiest way is by using a Category Template.

    https://codex.www.ads-software.com/Category_Templates

    Basically you want to have a category.php page, and then change
    <?php while ( have_posts() ) : the_post(); ?>

    to this
    <?php while (have_posts()) : the_post(); if (in_category($cat)) { ?>

    and
    <?php endwhile; ?>

    to
    <?php } endwhile; ?>

    See https://motioncity.com.ar/2008/wordpress-tip-how-to-exclude-children-categories-on-a-template/ for mroe details

    Thread Starter mystifier

    (@mystifier)

    Thanks Ipstenu, but I can remember trying this a long time ago.

    Although my template Main Content area is very simply

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    ....
    <?php endwhile; ?>

    After the mod, top-level categories show empty.

    I am not sure if this is a problem with my also using another category related plug-in: https://www.webspaceworks.com/resources/cat/wp-plugins/31/

    Very frustrating!!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Then it would be like this:

    <?php if (have_posts()) : while (have_posts()) : the_post(); if (in_category($cat)) { ?>
    
    ...
    
    <?php } endwhile; ?>

    That plugin shouldn’t matter.

    Thread Starter mystifier

    (@mystifier)

    That’s exactly what I have but it doesn’t work.

    EXAMPLE: https://www.burtongrammar.co.uk

    Select: School Staff >> (Life & Times Menu)
    The ONLY post in this category is https://www.burtongrammar.co.uk/?p=134
    That is ALL that showed before the update; now I get pages and pages of mis-ordered posts from all lower sub-categories

    Select: Bond Street (Theme)
    This has the mod applied. I get nothing in top-level menus (categories)!!

    I didn’t notice that things were so bad before I updated all websites, including the linked https://www.burton-on-trent.org.uk

    My kids school website, which has four or five level deep sub-categories is a total mess with EVERY child-category showing at the top level.

    WordPress might be okay for small blogs but suddenly, every website is completely unusable.

    (Same applies to Admin, Filter Posts by Category is a total mess now again showing pages and pages of EVERY child-category).

    Thread Starter mystifier

    (@mystifier)

    I don’t have $cat. I think it needs to be a call to get the current category, something like:

    if(in_category(get_current_category())){

    (which doesn’t work but I can’t figure out what does).

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    WordPress might be okay for small blogs but suddenly, every website is completely unusable.

    Tell Time that. It IS usable, but this is more of a themeing question, and I’m afraid I’m not the best at that.

    Maybe try the code from this: https://jivstudio.com/2010/12/02/show-only-parent-categories-on-wordpress-archives/

    Thread Starter mystifier

    (@mystifier)

    Nothing there that helps I’m afraid but I am grateful for your continued help.

    Plug-ins that hide child category posts have always been extremely popular and high download. This is because on websites where there are three or four levels of sub-category, it can soon result in many tens of posts showing unnecessarily at higher (hierarchical) levels. Without a plug-in, or better still, core fix, large websites ARE completely unusable.

    I have seven or so different wordpress sites and I can’t think of one example where this is sensible core behaviour and not having an option to hide them at least is very poor.

    The two websites given as examples receive in the order of 10000 pageviews/month, suffice to say that since I upgraded, I have received twenty-odd emails ‘informing’ me that the site navigation has stopped working.

    I can’t fix it and it is enough reason to wind back to an old version where plug-ins work again.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Plug-ins that hide child category posts have always been extremely popular and high download.

    Except all the ones you cite aren’t on the WP repository… Which is really odd and seems to contradict what you’re saying.

    More to the point, I think that people aren’t using categories to that degree anymore, and mostly due to the advent of tags. I have four categories on a pretty large site, and the rest is all sorted with tags in each category, or Custom Post Types. It’s an organizational shift, but I found people couldn’t FIND things if I had a surplus of categories.

    Still, I would post that question ‘How do I hide child categories in a category archive page?’ in the template section, where the much smarter template people live ?? I’m sure this is stupid easy, but it’s not my forte.

    I just updated Kinderlose, and tested it on 3.1.3. Let me know if there’s any problems with it.

    How about “exclude_pages” plugin? It works on pages, I don’t know about posts.

    Thread Starter mystifier

    (@mystifier)

    In the end, I figured out the field name change but in my original plug-in. This has been updated for 3.1+ by the author and is a very elegant solution:

    https://guff.szub.net/2007/11/30/kinderlose/

    Simple but essential!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Request: Hide Posts in Child Categories’ is closed to new replies.