Parent page highlighting – what am I doing wrong?
-
Hi, everybody.
I’m building a site that will have two buttons as navigation, with
wp_list_pages
generating sub-navigation beneath these two main pages using sub-pages.It’s listing the sub-pages just fine, but I can’t figure out how to give the parent pages a certain class while you’re on a subpage.
Right now it looks like this:
<?php global $wp_query; //check to see if current page has a parent: if( empty($wp_query->post->post_parent)) { $parent = $wp_query->post->ID; //if it doesn't, give it an ID of $parent } else { $parent = $wp_query->post->post_parent; //if it does, give its parent an ID of $parent } rewind_posts(); ?> <ul id="nav"> <li class="commercial"><a href="<?php bloginfo('url') ?>/downtown-commercial/" title="Downtown Commercial"<?php if(is_page('downtown-commercial') || $post->post_parent == $parent) : echo " class=\"active\""; endif ?>>Commercial</a></li> <li class="disaster"><a href="<?php bloginfo('url') ?>/disaster-restoration/" title="Disaster Restoration"<?php if(is_page('disaster-restoration') || $post->post_parent == $parent) : echo " class=\"active\""; endif ?>>Disaster Restoration</a></li> </ul>
and then the call for the subpages looks like this:
<?php if (is_page()) : if (wp_list_pages("title_li=&child_of=$parent&echo=0")) : ?> <ul id="subNav"> <?php wp_list_pages("title_li=&child_of=$parent"); ?> </ul> <?php endif; endif; ?>
Instead of applying the “active” class only to the current page parent, it adds it to both of them, and I can’t quite figure out why.
Any suggestions?
Thanks everybody!
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Parent page highlighting – what am I doing wrong?’ is closed to new replies.