WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] different menus on different pages (8 posts)

  1. ke vinritt
    Member
    Posted 4 years ago #

    On the site I have there are different side menus on different pages. Does anyone know a way or tutorial that will show me how I can dynamically generate this without having to create separate pages templates for each section. So for example, if you in the 'About' section there would be a side menu that would have...
    >Profile
    >contact
    > Request more info
    and so on but the 'Events' section would have...
    >Local events
    >Local restaurants
    and so on
    Any suggestions?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    http://wordpress.org/support/topic/364851?replies=2

    is a thread currently going on about using conditional sidebars, maybe that is a route you'd like to take?

  3. MichaelH
    Member
    Posted 4 years ago #

    Or something like this from my notes:

    For use in sidebar, display only top level Pages, but when viewing a Page that has children (or is a child) show only children of that parent

    When visiting main page, all top level pages are listed in the sidebar.

    When click on a top level page with no children, all top level pages are listed.

    When click on a top level page with children, just the children pages are listed.

    When click on a children page, just the children of that parent are listed.

    <?php
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>' );
    if (is_page( )) {
      $page = $post->ID;
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>');
      }
    }
    echo $output;
    ?>
  4. ke vinritt
    Member
    Posted 4 years ago #

    MichaelH,
    Do you have a live sample that I can see?

  5. MichaelH
    Member
    Posted 4 years ago #

    Nope.

  6. MichaelH
    Member
    Posted 4 years ago #

    If you don't want to put that in your sidebar.php, consider downloading and installing Otto's PHP Code Widget.

    Then put this in one of those widgets:

    <?php
    global $post;
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>' );
    if (is_page( )) {
      $page = $post->ID;
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>');
      }
    }
    echo $output;
    ?>
  7. photocurio
    Member
    Posted 3 years ago #

    It would be very useful if this sort of menu structure would be available with WordPress' new drag-and-drop menu admin system. Right now I only see child pages display as drop-downs. This puts every page available on every page. That is not always the best system.

  8. teknohippy
    Member
    Posted 3 years ago #

    I want different menus on different pages as well, I've just solved it with the new nav_menus and a little bit of theme tweaking. It's worked out nicely as I won't have to fiddle with the theme to add a new page and menu combination.

    In the theme I have:

    <?php wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) ); ?>

    Then in the page I simply have a custom field called "MenuName", which is set to match the name of the wordpress nav_menu I want used on that page.

    If a custom MenuName is not defined then it will fall back to the nav_menu assigned to that theme_location.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.