Hi! I'm trying to set up my header code to dynamically highlight the current page in the menu. To do this, I'm trying to assign a "currentpage" class to the menu item representing the current page or category, using "in_category" and "is_page". But they seem to be acting inconsistently.
I've set up this code at the top of my header.php:
<?php if ( in_category('1') ) {
$thisPage="blog";
} elseif ( in_category('3') ) {
$thisPage="library";
} elseif ( is_page('3') ) {
$thisPage="storetheatre";
} elseif ( in_category('4') ) {
$thisPage="events";
} elseif ( is_page('5') ) {
$thisPage="flamenco";
} elseif ( is_page('14') || in_category('10') ) {
$thisPage="aboutus";
} elseif ( is_page('8') ) {
$thisPage="contact";
} ?>
And added code to the menu along the lines of this:
<li<?php if ($thisPage=="storetheatre") {echo " id=\"currentpage\""; }?>><a href="http://ediehats.com/wordpress/?page_id=3">Store/Theatre</a>
But the "currentpage" code is being inconsistently applied. When I load a page and view the source, the "id=currentpage" gets applied only on these categories: Blog, Library, Events. In other words, only the category-based logic works. But for the page-based ones - Store/Theatre, Flamenco, About Us and Contact - it doesn't work. Instead, and strangely, the first menu item, "blog", has "currentpage" applied to it.
I was sure I was using the is_page syntax correctly but it seems not to be working here... and I can't imagine why!
Hope someone can point me in the right direction.