WordPress.org

Ready to get started?Download WordPress

Forums

show current page while on parent subpages (3 posts)

  1. fldtrace
    Member
    Posted 4 years ago #

    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>
                        <ul>
                        	<?php wp_list_pages('child_of=9&title_li='); ?>
                        </ul>
                  </li>
    
                    <li <?php if (is_page('contact') ) { echo ' class="current"'; } ?>><a href="<?php bloginfo('url');?>/contact"><span>Contact</span></a></li>
                </ul>

    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.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Why not just use the existing classes .current_page_parent and .current_page_ancestor?

  3. fldtrace
    Member
    Posted 4 years ago #

    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'); ?>
                </ul>

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

Topic Closed

This topic has been closed to new replies.

About this Topic