WordPress.org

Forums

WP 1.5 show/hide categories (16 posts)

  1. essdsm
    Member
    Posted 10 years ago #

    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

  2. essdsm
    Member
    Posted 10 years ago #

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

  3. Lorelle
    Member
    Posted 10 years ago #

    Anyone else tried this and had it work in 1.5?

  4. Kitten
    Member
    Posted 10 years ago #

    Basically, the trick w/ 1.5 is to use the is_category( $num ) function in an if statement to wrap your main loop. You can also negate it to exclude a category.

  5. essdsm
    Member
    Posted 10 years ago #

    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?

  6. dmac8283
    Member
    Posted 10 years ago #

    I guess I'd like to ask for an illustration of how to do this in 1.5 if it's possible, too. Thanks!

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

    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.

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

    Ok, the example was half baked. It should work now.

    And now there's an example for what you actually want!

  9. dmac8283
    Member
    Posted 10 years ago #

    Thanks so much!

  10. knitter
    Member
    Posted 10 years ago #

    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?

    thanks!

  11. ElephantWoman
    Member
    Posted 10 years ago #

    Try

    orderby=title&order=ASC

    For reference, this works for me (xxx what you whant) :

    <?php query_posts("category_name=xxx&orderby=title&order=
    ASC&showposts=xxx"); ?>
    <?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; ?>

  12. knitter
    Member
    Posted 10 years ago #

    thanks! any ideas on removing the posts of child categories?

  13. ElephantWoman
    Member
    Posted 10 years ago #

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

  14. knitter
    Member
    Posted 10 years ago #

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

  15. karmadude
    Member
    Posted 9 years ago #

    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?

    see http://blog.counterjumper.com

    the category I have hidden is Images

  16. kartlink
    Member
    Posted 9 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.