Hi
I'm trying to write an expression to display posts from some specific categories + on those categories' front page (eg site.com/category/posts + site.com/category)
This is the closest I've come:
'is_category(array(4,6,8)) || (is_single() && is_category(array(4,6,8)))'
where the numbers are those categories' ID's.
Something obvious I'm missing?
I've struggled a lot, so some help would be most appreciated!
Thanks,
Kjetil
PS It works partly on dolcevita.no - eg with the ads on the Toscana (category) overeview and a Toscana subpage (post) - showed using the very useful widget logic plugin
PS Yes I've searched and found several doc pages - like this, this and this.
Do you know of the power of Category Templates with the Template Hierarchy structure that might make your job easier?
Thanks Michael
I use a different category template for every category, it's a great "feature" and really important to know about. I believe I've also used the template hierachy well.
But instead of making eg. a different sidebar for each category template; I'm using the possibilities with Widget logic.
It should be possible to display one particular widget only in the sidebar of one category's archive/overview page + in posts associated with that category.
Or, in my case, in three categories.
But for this I really need the correct code.
Would be of great help
Thanks,
Kjetil
You mean like:
<?php
if ( is_category() ) {
$cat = get_query_var('cat');
if ($cat == 4) || $cat == 6 || $cat == 8) {
// do something special
}
}
?>
I could be, though it looks strange. I believe it would be something similar to the expression I showed initially:
'is_category(array(4,6,8)) || (is_single() && is_category(array(4,6,8)))'
Thanks a lot for making an effort :o)
Sorry, but the last expression, Michael, is not what I'm looking for.
I've tried some more back and forth, and this is the closest I've come:
'(in_category(4) || in_category (6) || in_category (8) || etc)'
It works - apart from the funny part that the test widget I try it with also shows up in categories that are not included (eg category 5 and 7), but just on those categories' overview/archive pages.
I would believe that something like my suggestion from yesterday or maybe just even simpler like
'is_category(4,6,8) || (is_single() && is_category(4,6,8))'
would work, but... nope.
Greatful if you could help me clear things up.
Kjetil
Paste your complete template (is it sidebar.php) in a pastebin and report the link back here. Maybe someone will spot the problem.