• Resolved moshu

    (@moshu)


    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

Viewing 15 replies - 1 through 15 (of 16 total)
  • 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.

    Thread Starter moshu

    (@moshu)

    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.

    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.

    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.

    Thread Starter moshu

    (@moshu)

    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 ??

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

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

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

    Thread Starter moshu

    (@moshu)

    @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!

    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); ?>

    Thread Starter moshu

    (@moshu)

    done.

    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.

    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).

    Thread Starter moshu

    (@moshu)

    It works like a charm. Thanks!

    Awesome. You’re welcome :)

    Thread Starter moshu

    (@moshu)

    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).

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Do not list children_cat posts in category view?’ is closed to new replies.