WordPress.org

Ready to get started?Download WordPress

Forums

Adding Submenu into my page template file (1 post)

  1. staceyzav
    Member
    Posted 2 years ago #

    Hello -
    I'd like my page template to do one of the following, depending on whether or not that page has child pages:

    • show the sub/child menu if you are on a child page
    • show sub/child menu you are on a parent page with a child menu
    • show the top-level menu if they are on a top-level page with no sub/child pages

    So far, I have the following code, which shows the sub/child menu if you are on a child page or a parent page with child pages. I cannot figure out the "if else" statement for showing the top-level menu if they are on a top-level page with no children.

    <?php
      if($post->post_parent) {
      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      $titlenamer = get_the_title($post->post_parent);
      }
    
      else {
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      $titlenamer = get_the_title($post->ID);
      }
      if ($children) { ?>
    
      <h2> <?php echo $titlenamer; ?> </h2>
      <ul>
      <?php echo $children; ?>
      </ul>
    
    <?php } ?>

    Thanks in advance for any help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.