WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Do not list children_cat posts in category view? (17 posts)

  1. moshu
    Member
    Posted 9 years ago #

    I've searched a lot, but couldn't find a solution.
    I have a home.php which works with query_posts and all is OK.
    I have in the sidebar a category list showing only parent categories even if they have children categories.
    Now when I click a category name in the sidebar/menu it will use the index.php to show
    a) all the posts from that category
    b) all the posts from (all) children categories
    What I'd like to achieve: to have listed/shown ONLY the posts from the parent category (that was clicked) and none of the posts from its children categories.
    I know I could use a category.php and exclude/include only the posts I want, but it would make my life easier if I can get this for every category.
    TIA

  2. skippy
    Member
    Posted 9 years ago #

    How are you showing your categories? wp_list_cats() supports a children=no option to disable showing children categories.

    And there's also get_category_parents(), which should show only the one category if called on a top-level category.

  3. moshu
    Member
    Posted 9 years ago #

    Thanks, but it isn't about showing the list of the categories - I managed that part.
    It is about not showing the POSTS from children categories when in the sidebar I click on the parent category's name.

  4. Lorelle
    Member
    Posted 9 years ago #

    I don't think that's exactly what you want in an answer, Moshu. I honestly think that the answer lies in those damn category conditional statements or category-1.php, etc. ;-)

    I'm not the conditional tag wizard in any respect, and while there are good descriptions in conditional tags article on the codex....there might be something in the Loop in Action that might serve you better.

    I'll ask around and see if I can get you a good answer, though.

  5. skippy
    Member
    Posted 9 years ago #

    what code are you currently using to get posts from current category plus children?

    I understand that the current behaviour is not what you want; but seeing what you're doing may help us find the solution you seek.

  6. moshu
    Member
    Posted 9 years ago #

    Sorry, it's on my local test install, I cannot show it.
    Basically what I wanted: let's say I have 5 categories displayed in the sidebar
    Africa
    America
    Asia
    Australia
    Europe
    There is only one post (or 2) in all of them.
    Now every category has subcategories... let's say "Mountains", "Rivers", "Countires" etc..
    The ideal thing would be if I click on "Africa" to show ONLY the post(s) from Africa, but NOT from its subcats.
    Unfortunately I couldn't find a working solution, so I went by creating category-1.php, category-2.php etc. and using query_posts with different parameters to get what I want. I guess I was hoping I can spare the creation of several category templates :)

  7. skippy
    Member
    Posted 9 years ago #

    I wasn't clear: show us the code in your index.php that you are using for your query_posts().

  8. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    moshu: I've written up something that might do the trick. Let me know.
    http://www.blogwaffe.com:8000/2005/05/31/294/

    This should work without extra templates and without a call to query_posts.

  9. moshu
    Member
    Posted 9 years ago #

    @mdawaffe,
    thanks, but it doesn't want to work on my site. All the clicks on categories in the sidebar give Error 404. All - parents, children.

    @skippy,
    coming soon... :)
    (but I don't use index anymore, on my local install I went by creating category-XX.php templates. Of course, that creates a "reverse" problem: now I need a query_posts that will show 1-1 post from each of the subcategories of the parent [where we are].)

    I really appreciate your help, guys!

  10. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    moshu: can you add something in your test site's footer.php? I guess your setup is a little different than mine; it might help debug.

    <?php global $wp_query; var_dump($wp_query); ?>

  11. moshu
    Member
    Posted 9 years ago #

    done.

  12. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Ok - I think I know the problem. I'm not quite sure where it enters, but I can fix it. Let me figure out the best way.

  13. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Ok - It should be working now...

    If you're copying and pasting from your browser, make sure you refresh. (A fresh download, of course, should work fine).

  14. moshu
    Member
    Posted 9 years ago #

    It works like a charm. Thanks!

  15. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Awesome. You're welcome :)

  16. moshu
    Member
    Posted 7 years ago #

    I know it's an old post (of mine).

    I have tried to use this plugin on a 2.0.5. install but it throws an
    Unknown column 'category_nicename' in 'where clause' etc... error.

    I figure it's not compatible with the latest WP version(s).

  17. moshu
    Member
    Posted 7 years ago #

    Ok, I found another plugin: http://ryowebsite.com/wp-plugins/nosubcats/
    (works with 2.0.5)

Topic Closed

This topic has been closed to new replies.

About this Topic