Forums

[resolved] Display current parent and its sub-menu only on sidebar (4 posts)

  1. Libin
    Member
    Posted 8 months ago #

    Hi,

    I am creating a website using wordpress 3.2.1 with twenty ten theme.

    I have a main navigation and all parents have children.
    Eg:
    Page A: Child 1
    Child 2
    Page B
    Child 3
    Child 4

    I need to include a horizontal submenu on sidebar. But my problem is, If currently we are on page A, all the child items of page A only to be displayed on sidebar.
    If we are on Page A, sidebar should looks like:
    Page A
    Child 1
    Child 2

    Like this, when we go to Page B, the child of page B only to be displayed.

    Please help me.

    Thanks in advance.

    Regards,
    Libin

  2. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    Don't edit the Twenty Ten theme. Instead create a child theme for your customisations. Once your child theme is active, see this Codex section.

  3. Libin
    Member
    Posted 8 months ago #

    Hey Esmi,

    Thank you so much for your help.
    Now I am working on a child theme and the following code fix my problem.

    <?php
      if($post->post_parent)
      $children = wp_list_pages("title_li=&child_of=".$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 } ?>

    But I need to display the current parent as the title for these sub menus. ie, I need the current parent page's name as heading. Please help me.
    Thank you so much for helping me.

  4. Libin
    Member
    Posted 8 months ago #

    Hey,

    I had figure out my problem by using the code below. This code will show the parent's name also as heading.!

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

    Once again thank you esmi for helping me.

Reply

You must log in to post.

About this Topic