WordPress.org

Support

Support » Themes and Templates » in_category not working on front page

in_category not working on front page

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

Viewing 12 replies - 1 through 12 (of 12 total)
  • try to pass the category as just number, with no ” before and after.

    Thanks.

    I tried that with the same result. 🙁

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

    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.

    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.

    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.

    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.

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

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

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

    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?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘in_category not working on front page’ is closed to new replies.