WordPress.org

Ready to get started?Download WordPress

Forums

Menu doesn't show child pages | wp_list_pages (3 posts)

  1. shalzers
    Member
    Posted 4 years ago #

    I am using this code to list pages in the menu.

    <?php wp_list_pages('depth=1&title_li=&sort_column=menu_order&excludetree=');?>
    				</ul>
    			</li>
               <ul id="submenu"><li><?php
    /*http://codex.wordpress.org/Template_Tags/wp_list_pages#List_subpages_even_if_on_a_subpage*/
      if($post->post_parent)
      $children = wp_list_pages("title_li=&child_of=&sort_column=menu_order, post_title".$post->post_parent."&echo=0");
      else
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
    
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?></li></ul>
    </div>

    The idea is for the menu to show the parent pages and it's children. It works on the parents page: http://www.metaphorm.org/new3/bio/ but if you go to a child page they disappear: http://www.metaphorm.org/new3/bio/artist-statement/

    Obviously PHP is not my strong point.

  2. shalzers
    Member
    Posted 4 years ago #

    Any PHP savants want to help a noob?

  3. shalzers
    Member
    Posted 4 years ago #

    Got it:

    Really the issue was listing other sibling pages of a child page.

    Solution:

    <!--- Menu -->
    <li id="menu">
    <ul>
    <?php wp_list_pages('depth=1&title_li=&sort_column=menu_order&excludetree=');?>
    				</ul>
    			</li>
    <ul id="submenu"><li><?php
         if($post->post_parent) { // if the current page has a parent
              $parent_title = get_the_title($post->post_parent);
              $parent_link = get_permalink($post->post_parent);
              $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");?>
    
    <?php } else { // if the current page is the parent
              $parent_title = get_the_title($post->ID);
              $parent_link = get_permalink($post->ID);
              $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); ?>
    <?php }
    	echo $children; ?>
            </li></ul>
    		</div>
    		<!--- /Menu -->

Topic Closed

This topic has been closed to new replies.

About this Topic