in_category: with multiple categories
-
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; }
- The topic ‘in_category: with multiple categories’ is closed to new replies.