WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Libin
    Member
    Posted 2 years 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
    Forum Moderator
    Posted 2 years 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 2 years 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 2 years 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.

  5. Rais khan
    Member
    Posted 2 years ago #

    Assalam-u-alaikum

    i have designed menu and submenus ,but submenues shows underneath the slider images when mouse is hover on the main menu.
    Anothor problem is that when we want to move from main menu item to its submenu ,then to leave the main menu item submenus of that item is automatically hides.
    please help me.....

  6. Libin
    Member
    Posted 2 years ago #

    Provide the link to your website to check it.

Topic Closed

This topic has been closed to new replies.

About this Topic