• Resolved FummeL

    (@fummel)


    Hi,

    Right now i have done a submenu with the following code:

    <?php
                  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
                  if ($children) { ?>
                  <ul id="sub-menu">
                    <?php echo $children; ?>
                  </ul>
              <?php } ?>

    The code displays and links submenu item pages. The problem is when i click on a submenu page i want the same menu on that page.

    Is there a way to write an IF statement that checks if the page is a submenu item, display the submenu for parent.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I did something very similar in one of my themes. I used the following in functions.php:

    // Generate page tree
    function purplepastels_page_tree($this_page) {
    	$pagelist = '';
    	if( !$this_page->post_parent ) {
    		$children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
    		if( $children ) {
    			$pagelist .= '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
    			$pagelist .= '<ul>' . $children . '</ul>';
    			$pagelist .= '</li>';
    		}
    	}
    	elseif( $this_page->ancestors ) {
    		// get the top ID of this page. Page ids DESC so top level ID is the last one
    		$ancestor = end( get_post_ancestors($this_page) );
    		$pagelist .= wp_list_pages('title_li=&include='.$ancestor.'&echo=0');
    		$pagelist = str_replace('</li>', '', $pagelist);
    		$pagelist .= '<ul>' . wp_list_pages('title_li=&child_of='.$ancestor.'&echo=0') .'</ul></li>';
    	}
    	return $pagelist;
    }

    The used:

    if( function_exists( 'purplepastels_page_tree') && purplepastels_page_tree($post) != '' ) :?>
    <div class="sub-pages"><h3><?php _e('Pages in this section', 'purplepastels');?></h3><ul>
    <?php echo purplepastels_page_tree($post);?></ul></div>
    <?php endif;?>

    in the relevant template file.

    Thread Starter FummeL

    (@fummel)

    esmi you are the best ??

    Hope it works for you. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Submenu on submenu page.’ is closed to new replies.