WP 1.5 show/hide categories
Kittens show_categories plugin no longer works in 1.5 and she isn’t planning an update because of the functionality now built into 1.5. Can someone provide me an example of how 1.5 can natively show or hide specific categories of posts, e.g. so I can create separate zones for different categories of posts on my front page? … Many thanks
I can’t find any integration of Kitten’s show/hide categories plugin in 1.5, which is a bit of suprise (it may just be me not looking hard enough). Anyway, in the absence of an apparent solution I’ve made minor modifications to her show_categories plugin which appears to make it compatible with WP 1.5.
It seems to have been a table variables issue, i.e. changing all references to $tableposts to $wpdb->posts and $tablepost2cat to $wpdb->post2cat appears to have done the trick. I think that the global variable declarations for $tableposts and $tablepost2cat at the top of both plugin functions were no longer relevant so I removed them. I suspect WP1.5 contains native functions which could improve the efficiency of the script for parsing the cats array but I’ll leave that job to someone who knows 1.5 better than me:)
I include the modified show_categories plugin script below. It would be nice to find this as standard WP functionality in the near future (or that I was wrong and it’s actually already there but undocumented) because it increases template design flexibility no end.
[Moderated: Script code removed. Please use http://paste.uni.cc to post long code examples.]
Basically, the trick w/ 1.5 is to use the
is_category( $num )function in an
ifstatement to wrap your main loop. You can also negate it to exclude a category.
Kitten … Thanks for this but I’m afraid there’s a bit of a conceptual leap for happening here. The barebones example of the 1.5 loop in the codex would benefit from just such an example. Could you possibly illustrate what you mean?
I guess I’d like to ask for an illustration of how to do this in 1.5 if it’s possible, too. Thanks!
http://codex.wordpress.org/The_Loop now has an example dealing with styling the post content differently if the post belongs to a certain category. The example is tailored to version 1.5.
A similar technique could be used to display only certain categories.
Ok, the example was half baked. It should work now.
And now there’s an example for what you actually want!
I have managed to create the effect that I want using the last example code posted by Ryan in the first part of the advanced use info on the Loop http://codex.wordpress.org/The_Loop and it is working but I have to questions.
1) are there more parameters I can use, in particular to sort the result by name or id?
2) how do I exclude the posts that are from child categories of the cat I have specified?
For reference, this works for me (xxx what you whant) :
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
thanks! any ideas on removing the posts of child categories?
Iâ€™m afraid none.
It should be simple, when using “cat=xx” to tell wp to exclude other categories other than xx but I really don’t see how.
(For reference, if ID is prefered then “cat” instead of “category_name”. And for showing all posts “showposts=-1”)
thanks for that! i had figured out how to use id with some fiddling round but hadn’t figured how to show all (other than setting a high limit I knew wouldn’t be crossed). I shall have to rethink my category structure… I had this all working beautifully with Kitten’s plugin, it seems to me that it is not so redundant after all…
I used the is_category function to hide the category, but on the index page, the navigation is somehow still counting the posts from the hidden category. So I get a blank page. How do I fix the page navigation code?
the category I have hidden is Images
I’m using the code found here http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category to exclude a category (the one it says is OK to use without a new category archives template) and I’m getting an error:
Parse error: parse error, unexpected T_ENDWHILE in /home/kartlink/public_html/pro/wp-content/themes/gentle_calm/index.php on line 44
- The topic ‘WP 1.5 show/hide categories’ is closed to new replies.