• 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
    /*https://codex.www.ads-software.com/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: https://www.metaphorm.org/new3/bio/ but if you go to a child page they disappear: https://www.metaphorm.org/new3/bio/artist-statement/

    Obviously PHP is not my strong point.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shalzers

    (@shalzers)

    Any PHP savants want to help a noob?

    Thread Starter shalzers

    (@shalzers)

    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 -->

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Menu doesn’t show child pages | wp_list_pages’ is closed to new replies.