tags:

views:

71

answers:

2

Hi I am trying to have the navigation highlights determined by what category or page you are looking at using wordpress. Can someone tell me what is wrong with a statement like this:

<?php if (in_category('b')){ ?>
<ul>
<li><a href="#">A</a></li>
<li><a class="current" href="#">B</li>
</ul>
<?php } else { ?>
<ul>
<li><a class="current" href="#">A</a></li>
<li><a href="#">B</li>
</ul>
<?php } ?>

I am trying to use something like this but my else statement is ignored and the 'b' is always current regardless of category.

A: 

read here.

You've got to write something like:

<?php if (in_category('b')): ?>
  <ul>
  <li><a href="#">A</a></li>
  <li><a class="current" href="#">B</li>
  </ul>

...
joni
Thanks but I tried that too and it makes no difference. I think that is just alternate syntax, reading preference..
zac
I didn't think that your syntax even works... PHP is a strange language. In this case, it's a logic error somewhere.
joni
The alternative syntax is not required for wordpress, it's just the way they like to write it.
Scott
+2  A: 

You are either not inside a post or everything is in category 'b'.

See http://codex.wordpress.org/Function_Reference/in_category for in_category() information.

Scott
No everything is not in cat b and I am not sure what you mean by not inside a post. This can be done outside the loop as it shows in that link.
zac
`This tag can be used to test the current post within The Loop` If you are in The Loop, in_category() will test the current post against the category. If you are outside The Loop, you should provide the post id as the second argument.
Scott
Ah ha. Thank you!
zac