Support » Fixing WordPress » show current page while on parent subpages

  • Hi, I have a static navigation that shows something like this:

    <ul id="main_menu">
                	<li <?php if (is_page('home') ) { echo ' class="current"'; } ?>><a href="<?php bloginfo('url');?>/home"><span>Home</span></a></li>
                    <li <?php if (is_page('structure') || is_page('child_of=9') ) { echo ' class="current"'; } ?>><a href="<?php bloginfo('url');?>/structure"><span>Structura</span></a>
                        	<?php wp_list_pages('child_of=9&title_li='); ?>
                    <li <?php if (is_page('contact') ) { echo ' class="current"'; } ?>><a href="<?php bloginfo('url');?>/contact"><span>Contact</span></a></li>

    I use php code to echo class current to the li when I am on that specific page, as you can see in the code.

    The “Structure” section displays the children pages dinamically. I tried to use the same code:

    is_page('child_of=9') where 9 is the id of the parent page but it doesn’t works.

    What I try to accomplish, is echo class current to the li of the parent page, while on any of its subpages.

    Thanks for help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Why not just use the existing classes .current_page_parent and .current_page_ancestor?

    Thanks for info,

    I reduced the code to:

    <ul id="main_menu">
                <?php wp_list_pages('&title_li=&link_before=<span>&link_after=</span>&depth=0'); ?>

    and css is bit bigger now, because I had to reset more child elements but it works great.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show current page while on parent subpages’ is closed to new replies.