• ellentolsma

    (@ellentolsma)


    Hi there,

    I’m trying to call different navigation menus for different landing pages but I’m stuck.. Here’s what I’ve done up to now:

    1. Registered secondary navigation in functions.php :

    register_nav_menu('game_nav', THEME_NAME . ' Game Navigation');

    2. Created a dedicated page template for the secondary landing page as page-game.php

    So far, so good. Both the secondary menu & page template show up at the backend of the site. All I need to do now – as far as my understanding goes – is to call the different menus in an else/if statement in header.php which I tried to do like below, but all goes wrong…My site now just shows up with a logo but no nav menu or home page load. Sorry, site is not live yet so link is not helpful..

    <?php if (is_page_template('page.php')){
    				wp_nav_menu( array(
    				'sort_column' => 'menu_order',
    				'container' => false,
    				'theme_location'  => 'main_nav',
    				'menu_id' => 'nav'));
    				}
    				elseif (is_page_template('game-page.php')){wp_nav_menu( array(
    				'sort_column' => 'menu_order',
    				'container' => false,
    				'theme_location'  => 'game_nav',
    				'menu_id' => 'nav'));
    				}
    				else {
    				echo theme_generator('menu');
    				}
    				?>

    The original was:

    <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => false, 'theme_location' =>'main_nav', 'menu_id' => 'nav')); ?>

    Any help would be much appreciated!

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    Try:

    <?php if (is_page_template('game-page.php')){
    	wp_nav_menu( array(
    		'sort_column' => 'menu_order',
    		'container' => false,
    		'theme_location'  => 'game_nav',
    		'menu_id' => 'nav')
    	);
    }
    else {
    	wp_nav_menu( array(
    		'sort_column' => 'menu_order',
    		'container' => false,
    		'theme_location'  => 'main_nav',
    		'menu_id' => 'nav')
    	);
    }?>
    Thread Starter ellentolsma

    (@ellentolsma)

    Thanks Esmi, getting closer ??

    My header + primary navigation menu is back but when I go to the ‘other’ landing page, the secondary navigation menu is not showing. To create a dedicated page template for this landing I basically copied the exact code of page.php but saved & added it to the template under another name: game-page.php. At page attributes WP now allows me to pick either ‘default template’ or ‘Game’ but it’s not connecting that page template to the secondary nav menu for some reason…

    What am I missing..?

    esmi

    (@esmi)

    Have you reviewed custom page templates?

    Thread Starter ellentolsma

    (@ellentolsma)

    I have – yes. Here’s the code of the custom page template I have made:

    <?php
    /*
    Template Name: Game
    */
    ?>
    
    <?php
    
    $theme_page_type=get_meta_option('theme_page_type');
    if($theme_page_type=='2') return require(THEME_DIR . "/template-blog.php");
    
    ?>
    
    <?php get_header(); ?>
    
    <?php tf_supersized(); ?>
    
    <section id="main-wrap">
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<div class="container">
    
    			<?php if(get_meta_option('display_title')!='off'): ?>
    
    			<div class="sixteen columns">
    
    				<h1 id="post-title"><?php the_title(); ?></h1>
    
    			</div>
    
    			<?php endif; ?>
    
    			<?php  $layoutType=get_post_meta(get_the_id(), 'layout-type', true); ?>
    
    			<?php if($layoutType==16 || $layoutType==''): ?>
    
    				<div class="sixteen columns">
    
    					<?php the_content(''); ?>
    
    				</div>
    
    			<?php else: ?>
    
    				<div class="twelve columns">
    
    					<?php the_content(''); ?>
    
    				</div>
    
    				<aside class="four columns">
    
    					<?php get_sidebar(); ?>
    
    				</aside>
    				<br class="clear">
    
    			<?php endif; ?>	
    
    		</div>	
    
    	<?php endwhile; ?>		
    
    <?php get_footer(); ?>

    Would it help if I’d call the secondary navigation menu in this page’s .php? Or do I need to (also) create a new function for the secondary navigation on function.php?

    Thanks ??

    Thread Starter ellentolsma

    (@ellentolsma)

    Still struggling with this one – any suggestions?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Calling different navigation menus for different pages’ is closed to new replies.