WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove SubCat posts from Category pages (13 posts)

  1. TomEnns
    Member
    Posted 2 years ago #

    Hey guys, i knwo this has been asked before but i was not able to find a recent article that was understandable. Basically i have a hierarchical way of organizing my site, but the problem is all of my subcategories are being shown in my main category pages, this is really making things look bad. What must i do to make it so that a category will only show posts that are in the category itself and not in subcategories of that category?

    To be honest a plugin that allowed this on a per category basis would be awesome, but i realize that is probably not available so if there is a plugin that works for this please let me know, otherwise what must i change in the template file?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

  3. TomEnns
    Member
    Posted 2 years ago #

    I have tested it out and it doesnt seem to work :/ I dont know if im doing something wrong or not, i installed the plugin and it says it should work automatically right?

  4. TomEnns
    Member
    Posted 2 years ago #

    heres a link to whats happening: http://ouyadb.com

  5. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with the add_filter in php tags :

    <?php add_filter( 'posts_where', 'ft_nscp_mod_where' ); ?>

    and

    <?php remove_filter( 'posts_where', 'ft_nscp_mod_where' ); ?>
  6. TomEnns
    Member
    Posted 2 years ago #

    well, this may sound really dumb of me, but where do i put these tags? Im assuming in the catagory.php file?

  7. TomEnns
    Member
    Posted 2 years ago #

    Right before and after the loop?

  8. keesiemeijer
    moderator
    Posted 2 years ago #

    Yes put it before and after the loop in your theme's category.php.

    Not sure this will work on your front page though (index.php).

  9. TomEnns
    Member
    Posted 2 years ago #

    It worked!!!!!! thankyou so very much, I have one more question for you though, is there a way i can do this for certain catagorys only? or is it only a global thing?

  10. TomEnns
    Member
    Posted 2 years ago #

    The index page is a custom page so it doesnt work there your right but that is a matter of adding a seperate catagory for what i want posted there which is no big deal :)

  11. keesiemeijer
    moderator
    Posted 2 years ago #

    is there a way i can do this for certain catagories only?

    Try it with the conditional tag is_category(): http://codex.wordpress.org/Function_Reference/is_category
    [untested]
    before the loop

    <?php
    // don't show sub categories on these categories IDs
    $no_sub_on_cats = array('22','25','44');
    
    if(is_category( $no_sub_on_cats )){
    add_filter( 'posts_where', 'ft_nscp_mod_where' );
    }
     ?>

    and after:

    <?php
    if(is_category( $no_sub_on_cats )){
    remove_filter( 'posts_where', 'ft_nscp_mod_where' );
    }
    ?>
  12. TomEnns
    Member
    Posted 2 years ago #

    You are a life saver my friend, this works like a charm :)

  13. Mladen Gradev
    Member
    Posted 2 years ago #

    @keesiemeijer

    Thank you very much :) I am so happy that i have made it with your help.

Topic Closed

This topic has been closed to new replies.

About this Topic