WordPress.org

Ready to get started?Download WordPress

Forums

in_category not working on front page (13 posts)

  1. nmallory
    Member
    Posted 8 years ago #

    O.K. I really did try to use the search function but I must be search-function-challenged because I could never get it to do more than pull up the stuff I'd already read in the Codex.

    Anyway, so I'm using in_category('category_id') in my code as I have on other blogs in the past successfully. I want to do a different css if one of the categories is "featured" or 20.

    This seems to work when the site is on an individual post (there is no separate single post page) but when you are on the main index, it seems to miss the category.

    Here's the code I'm using:

    <?php if (is_single()) : ?>
    <div class="postsingle" id="post-<?php the_ID(); ?>">
    <?php else : ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <?php endif; ?>
    <?php if ( in_category('20') ) : ?>
    <div class="titolofeatured">
    <?php else : ?>
    <div class="titolopost">
    <?php endif; ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>

    Here's the link to the page The Naked Truth. "The Conspiracy Superstition" half way down is a "featured" post.

    What am I missing? I know it's something small and embarrassing. ;)

    Thanks in advance!

  2. sadish
    Member
    Posted 8 years ago #

    try to pass the category as just number, with no '' before and after.

    Thanks.

  3. nmallory
    Member
    Posted 8 years ago #

    I tried that with the same result. :(

  4. Michael_
    Member
    Posted 8 years ago #

    Hmm, isn't it is_category() instead of in_category() according to http://codex.wordpress.org/Conditional_Tags ?

  5. nmallory
    Member
    Posted 8 years ago #

    eh. I'm working on a different theme anyway. Still I'd like to know why that refused to recognize the "featured" category except when it was posting an individual post.

  6. sadish
    Member
    Posted 8 years ago #

    in_category(4), checks if the current post, belongs to category with an id of 4.

    is_category() is true, when you are viewing posts from one particular category.

  7. nmallory
    Member
    Posted 8 years ago #

    OK New design, still doesn't work. I want to check if my posts are in the "featured" category, though they will also have other categories they are attached to. If it is in the "featured" category, I want to use a different css for the title.

    This just doesn't appear to work on the home page. The in_category(20) never comes back true.

  8. MichaelH
    Member
    Posted 8 years ago #

  9. nmallory
    Member
    Posted 8 years ago #

    Yup. Same as mine.

    <?php if( in_category(20) ) : ?>
    <div class="divTitleF">Featured: <?php the_title(); ?></div>
    <?php else : ?>
    <div class="divTitle1"><?php the_title(); ?></div>
    <?php endif; ?>

    Have tried it with the braces {}. Have tried it with '20' and just plain 20.

  10. nmallory
    Member
    Posted 8 years ago #

    In case anyone cares, it appears that Adhesive plugin disables in_category().

  11. raianoat
    Member
    Posted 8 years ago #

    nmallory,
    Thanks for giving the solution to this problem. I was going nuts until I found this thread.

  12. thomet
    Member
    Posted 8 years ago #

    Damn, that Adhesive plugin is so useful and yet it breaks a lot of other good stuff.

  13. FurrTrap
    Member
    Posted 8 years ago #

    triple drat, so it's adhesive that breaks it...

    I just wish there was a really simple way of not displaying a group of categories on the front page as easy as it is to add cat exclusions in wp_list_cats() for use in the sidebar...

    front_page_cats.phps v0.2 by Ryan Boren seems unstable (ok it's in dev) and conflicts with pluggable_functions.php it also munges the left-hand padding of a right float in Win/IE6...

    UGH!

    Does anyone have a simple solution to hold back the display of a GROUP of categories on the front page without affecting the post counter and that doesn't get stuffed by the adhesive plugin?

Topic Closed

This topic has been closed to new replies.

About this Topic