Forums

[resolved] Limiting The loop to Parent only OR child (2 posts)

  1. greg2008
    Member
    Posted 2 years ago #

    I have spent a day searching, but to no avail.

    I have an area on my site which when the user clicks on a category, I want it to only show them posts from that category, no children posts or other.

    I have a parent category called "Money", which has 2 child categories - "Funds" & "Wealth".

    Money/
    Money/Funds/
    Money/Wealth/

    I've got this working:
    query_posts('cat=10');
    This does show only this category, but unfortunately it also shows the children of it.
    And when I click on any of the child cats of this parent, it also shows posts from the parent cat and ALL child cats of the parent (not just the one I clicked on).

    Now I can explicitly list each category ID I don't want to show or ONLY want to show, but doing this each time I edit or add a child of the parent is annoying, and not very practical to be honest.

    I also don't want these to show in any other loops, I.E. the homepage or other category loops.
    So only show them when they are specifically clicked on.

    Again, using query_posts() I can eliminate certain cats on the index and other places I have the loop, but I also then have to edit these theme files to add these new IDs to stop them being shown.

    Any advice?

    To LIMIT them being shown (in index etc), it would be great if I could simply somehow "limit the parent and all children", without having to specifically list all IDs I want to not show.

    And is there also any way to only SHOW the parent or one of the child cats when the user clicks on it WITHOUT having to edit the theme each time and add the IDs to the clauses?

    Any ideas very much welcomed, as I've tried many things and scoured for a long time.
    Cheers

  2. greg2008
    Member
    Posted 2 years ago #

    Update!

    Using this plugin has helped.

    Now the child categories are not listed when users view a parent, they have to specifically click the child link to see articles for that category.

    And interestingly enough, it also seems to have solved the issue of LIMITING this entire area from being listed in other areas.
    On the homepage (index.php) I have a basic loop to show all posts from all cats. With query_posts('cat=-10'); in conjunction with this plugin, the category "10" and all child cats seem to have now been banished!

    So I can add new cats or rename them to that one parent cat and don't have to edit the theme files all the time to limit all the IDs!

    Hopefully this will help someone else.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.