I'm trying to make a condition that creates sidebar content if a specific category archive is being viewed OR if a post in that category is being viewed.
I was thinking this would work but it's not:
<?php
$post = $wp_query->post;
if ( in_category(19) || is_category(19) ) : ?>
DO SOME STUFF
<?php endif; ?>
Any suggestions?
Thanks,
Sean
Hello
<?php if (is_category('19') || in_category('19')) { ?>
DO SOME STUFF
<?php } ?>
That should work! :)
I want no just one category that not show? how to do that? that I mean, I have 15 and 19 category, and I don't want this category show up in front my page.
How to do that?
acousticdryad
Member
Posted 5 years ago #
<?php if ( !(in_category('29')) ) { ?>
<?php } ?>
Should exclude category 29.
PaulWeber
Member
Posted 5 years ago #
Interesting.
Is there anything like an "AND" condition?
I.e. if variable 1 AND variable 2 are true, then display content X
else if variable 3 AND variable 4 are true, then display content Y?
Thank you - it would be precious help!
Paul Weber
aaronsportfolio
Member
Posted 5 years ago #
Paul, here is a solution:
<?php
if (is_category('xyz')) {
Do something;
}
elseif (category('xyz2')) {
Do something else ;
}
elseif (category('xyz3')) {
Do something else;
}
else {
Do something if none of the above are true;
}
?>
- is_category can be replaced with any other conditional tag, ex: is_single('some single post') OR is_post('some post')
smoczokwik
Member
Posted 4 years ago #
Paul another option is
<?php
if ($1 == TRUE && $2 == TRUE) {
echo "something";
} elseif ($3 == TRUE && $4 == TRUE) {
echo "something else";
} else {
echo "something completely different";
}
?>