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.
http://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); ?>
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).