• Resolved jamesalton

    (@brettalton)


    I’m trying to have one div/ul print the menu and if the current page the user is on has sub-pages, print those to.

    (I have that working).

    What I don’t have working is how to keep the sub-page highlighted (I can do this via CSS) when we’re actually viewing the page.

    e.g.

    menu –> Home (id=1), About Us (id=2, selected)
    submenu –> Staff (id=12), History (id=14, selected)

    and have the menu up when About Us –> History is selected.

    Here’s my code:

    <div id="menu-wrapper">
    	<div id="menu">
    		<ul id="nav">
    			<?php wp_list_pages('sort_column=menu_order&title_li=&depth=1')?>
    		</ul>
    	</div><!-- menu -->
    </div><!-- menu-wrapper-->
    
    <?php if (wp_list_pages('&child_of='.$post->ID.'&echo=0')) { ?>
    <div id="submenu-wrapper">
    	<div id="submenu">
    		<ul id="nav">
    			<?php wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'')?>
    		</ul>
    	</div><!-- submenu -->
    </div><!-- submenu-wrapper-->
    <?php } ?>

    The whole submenu-wrapper div disappears when I have a child page selected.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jamesalton

    (@brettalton)

    I don;t think that is what I was looking for, or, at the very least, I don’t understand that at all. I just need a simple fix for wp_list_pages() so when a sub-menu item is clicked, the sub-menu still appears.

    e.g. this would need to be fixed:

    <?php if (wp_list_pages('&child_of='.$post->ID.'&echo=0')) { ?>

    Thread Starter jamesalton

    (@brettalton)

    I figured it out

    <div id="menu-wrapper">
    	<div id="menu">
    		<ul id="nav">
    			<?php wp_list_pages('sort_column=menu_order&title_li=&depth=1')?>
    		</ul>
    	</div><!-- menu -->
    </div><!-- menu-wrapper-->
    
    <?php
    
    // subpage has been selected
    if ($post->post_parent)
    {
    	// show children of selected page
    	$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1');
    }
    // parent page has been selected
    // check if there are any child pages
    else
    {
    	// show children of current parent page
    	$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
    }
    
    // if there are subpages, print them
    if ($children) {
    
    ?>
    <div id="submenu-wrapper">
    	<div id="submenu">
    		<ul id="nav">
    			<?php echo $children ?>
    		</ul>
    	</div><!-- submenu -->
    </div><!-- submenu-wrapper-->
    
    <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Menu/submenu woes’ is closed to new replies.