• Hey all!

    Ive been searching the topics with in_category questions to solve a little problem im encountering but i cant seem to find a solution.

    Im using in_category() functions to change the layout of my site for some posts.
    I have a “blog”, “articles” and “classes” pages. When you see the “blog” you get all sorts of posts, whereas on “articles” you see posts that only appear on the “articles” page.
    So far so good.

    My problem is on the “classes” page, when listing the posts i get a specific color for my header an links, but once you click on a specific post it shows the “blog” color.

    My guess is that, because those posts belong to more than one category (the “articles” posts have only the articles cat), its messing up with the color-choosing function.

    In short: When using in_category(), if the post belongs to more than one category, the function doesnt help.

    Is there a way to bypass this problem?

    Thank you for your time.

    ps: this is my function (cleaned up) and uses…

    function getColorScheme() {
    if (is_Page(‘articles’) || in_category(4)) { $color = “articles”; }
    elseif (is_Page(‘classes’) || in_category(23)) { $color = “classes”; }
    else { $color = “blog”; }
    echo $color;
    }

    i put it as a class on my <body>
    <body class=”<?php echo getColorScheme(); ?>” >

    so it changes my CSS
    .blog A { color: #783e6e; }
    .articles A { color: #842222; }

Viewing 3 replies - 1 through 3 (of 3 total)
  • I would like to do this too. I also noticed that in_category doesn’t work for multiple categories.

    I tried:

    <?php
     $post = $wp_query->post;
     if ( in_category(14) && in_category(3) ) {
     include(TEMPLATEPATH . '/single_current.php');
     } else {
     include(TEMPLATEPATH . '/single_back.php');
     }
     ?>

    WordPress ignores the AND operator here.

    Oh man, hasn’t there been a solution yet? I’m making a magazine type website and even though I use template files for category-7.php or so, whenever I assign a post to multiple categories, it only comes up in one of them.

    instead of AND (&&) use OR (||)
    it works for me on WP 2.6.2

    <?php
     $post = $wp_query->post;
     if ( in_category(14) || in_category(3) ) {
     include(TEMPLATEPATH . '/single_current.php');
     } else {
     include(TEMPLATEPATH . '/single_back.php');
     }
     ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘in_category: with multiple categories’ is closed to new replies.