Forums

[resolved] Different menus on different pages (14 posts)

  1. bloggitivity
    Member
    Posted 1 year ago #

    I've found similar topics but none with suggestions/answers that worked for me.

    Here is what I am looking for: my start page is a static page that lets you choose whether you want to go to section "A" or section "B" of the website.
    Section "A" holds a number of static pages, with sub-page hierarchies.
    Section "B" holds the actual blog, with different pages for different categories.

    I want to use the "Below Title"/Secondary Menu in the header, showing a different menu depending on where you are.

    All pages in section A should show a menu displaying the section A pages and the link to the blog; not the remaining section B pages.

    All pages in section B should show a menu displaying the section B pages and a link back to the start page; none of the section A pages.

    Working on the 3.2.1 build with the Comet theme, at the moment locally with MAMP (so no link to the site).

    Hope someone has the decisive tip.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    You could load different sidebars template files based on the is_page() conditional - eg:

    if( is_page() ) get_sidebar( 'sidebar-pages');
    else get_sidebar();
  3. bloggitivity
    Member
    Posted 1 year ago #

    Two things.

    1. Sidebar for a menu in the header? Is that the right approach?

    2. I appreciate the suggestion, any suggestion, but this is extremely vague. At least for my limited coding experience. It's like I am at point A and need to get to F, and you suggest E, which would lead to F, but leave out step B, C and D.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    1. Yes. In WordPress, a sidebar has developed to mean any area that can hold widgets (many of which relate to navigation) rather than a physical bar at the side of a given web page.

    2. The Codex has just about everything you need.
    http://codex.wordpress.org/Function_Reference/get_sidebar
    http://codex.wordpress.org/Function_Reference/is_page
    http://codex.wordpress.org/Theme_Development

  5. bloggitivity
    Member
    Posted 1 year ago #

    1. Alright. Thanks for clarifying.

    2. I know it's probably well meant, but a "go look it up and piece it together yourself" suggestion wasn't what I was hoping for from asking here. That's what I've been trying these past days and it didn't get things to work. As I mentioned above: coding experience is there, but it is limited.

    Maybe someone has had the same problem and found a solution - or has done the same thing and never saw it as a problem - and can share the solution.

    I know it shouldn't be too much coding, but I'm just not getting the code right and/or put it in the wrong place.

  6. bloggitivity
    Member
    Posted 1 year ago #

    Or maybe someone can point out where my mistake is in my current approach.

    Step 1, I need to register one of the two menus I want to use (no need to register both, since I can use the already registered default (called "Below Title") as the second menu, correct?).

    So in the functions.php, what looked like this:

    register menus
    */
    add_action( 'init', 'register_my_menus' );
    
    function register_my_menus() {
    	if ( function_exists('register_nav_menus') ) {
    		register_nav_menus( array('primary-menu' => 'Above Title','secondary-menu' => 'Below Title',) );
    	}
    }

    Should become

    register menus
    */
    add_action( 'init', 'register_my_menus' );
    
    function register_my_menus() {
    	if ( function_exists('register_nav_menus') ) {
    		register_nav_menus( array('primary-menu' => 'Above Title','secondary-menu' => 'Below Title', 'Custom' => 'custom', ) );
    	}
    }

    Then in the page.php, I add this:

    <?php if( is_page(array(9,11,13,15)) ) get_sidebar( 'custom');
    else get_sidebar(); ?>

    With 9,11,13,15 (and potentially more) being the page IDs of the pages I want this custom menu to replace the default menu (the secondary menu/below title).

    And then I need a new php that defines the custom menu to be located where the secondary menu is? Yes? No? If so, what needs to be in there?

  7. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    You are currently registering a new custom menu location - not a new sidebar. Is that what you want?

  8. bloggitivity
    Member
    Posted 1 year ago #

    I'll try to explain again.

    In the theme I am currently using (Comet) supports two different locations for navigation menus by default (located in the header, not in the widget area/sidebar).
    One of them is above the page title, one of them below the title.

    I want to use the navigation menu called "Below Title".

    For one group of pages, I want a menu that displays only those pages ... in that very location.
    For the second group of pages, I want a menu with different entries ... but in the same location.

    I am now looking for a way to define: all pages of group "A" will display menu "A" in the "Below Title" location while all pages of group "B" will display menu "B" in the "Below Title" location.

  9. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    First you need to decide how you want to generate this menu - via a custom menu or using something like a widget in a sidebar.

  10. bloggitivity
    Member
    Posted 1 year ago #

    Custom menu was my first thought. They are convenient to set up and maintain.

    But honestly, I'm not opposed to a different solution.

  11. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    If you want a custom menu, then you don't call it using get_sidebar() but using wp_nav_menu().

  12. bloggitivity
    Member
    Posted 1 year ago #

    Nope, that isn't the solution either.

  13. bloggitivity
    Member
    Posted 1 year ago #

    New development:

    I have switched to the "Nest" theme, which natively supports one navigation menu location.

    In the header.php, I have added the following code

    <?php if( is_page(array('9,11,13,15')) ) wp_nav_menu( 'a');
    else wp_nav_menu('b'); ?>

    With "a" and "b" representing the two menus I have defined in the Appearance > Menu area of the WP backend.

    This has the effect, that menu A is displayed instead of the default menu of all pages. So partial success.
    BUT menu A is now displayed on all pages, not just just those with the page IDs I have defined.

  14. bloggitivity
    Member
    Posted 1 year ago #

    Found the solution myself.

Topic Closed

This topic has been closed to new replies.

About this Topic