Ask your WordPress questions! Pay money and get answers fast! (more info)

Show different Menu on specific page template (responsive) WordPress

  • SOLVED

Hi,

I'm using Modernize Premium Theme and am trying to "split" my site into two areas with different navigation menus on each. The theme has two build in menus and I want one of them, "main-menu", to switch to another menu when a specific page template is used. To achieve this I have registered another menu called "alternate-menu" in functions.php and have created a page template called "alternate-page". So far so good. However, since the navigation menu is called in the header.php I have tried to implement a conditional tag that goes something like this: if is page_template (alternate-page.php), then..."alternate-menu", else..."main navigation". and this is where I fail. since the menu is also responsive and my knowledge of php only rudimentary, I keep getting errors, because there already is a conditional tag in place and I don't know where & how to add another.

Here is the part of my header.php where the navigation menu is called:

<!-- Navigation and Search Form -->


<div class="main-navigation-wrapper">
<?php
if( $gdl_is_responsive ){
echo '<div class="responsive-container-wrapper container-wrapper">';
dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'indent_string' => '- ', 'indent_after' => '','container' => 'div', 'container_class' => 'responsive-menu-wrapper', 'theme_location'=>'main_menu') );
echo '</div>';
}
?>
<div class="navigation-wrapper">
<div class="navigation-container-wrapper container-wrapper">
<!-- Get Navigation -->
<?php wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'main_menu' ) ); ?>

<!-- Get Search form -->
<?php if(get_option(THEME_SHORT_NAME.'_enable_top_search','enable') == 'enable'){?>
<div class="search-wrapper"><?php get_search_form(); ?></div>
<?php } ?>

<div class="clear"></div>
</div> <!-- navigation-container-wrapper -->
</div> <!-- navigation-wrapper -->
</div>


I hope my question makes sense and will be a no-brainer for an expert. If my way is stupid and I should try something altogether different- please let me know.

Answers (3)

2014-03-27

Bob answers:

your logic is proper
here is full code that should go in header.php file
<strong>Note you have to put condition at tow places. they are generating responsive menu by dropdown_menu function</strong>

<!-- Navigation and Search Form -->

<div class="main-navigation-wrapper">

<?php

if( $gdl_is_responsive ){

echo '<div class="responsive-container-wrapper container-wrapper">';
if( is_page_template('alternate-page.php') ){

dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'indent_string' => '- ', 'indent_after' => '','container' => 'div', 'container_class' => 'responsive-menu-wrapper', 'theme_location'=>'alternate-menu') );

}else{

dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'indent_string' => '- ', 'indent_after' => '','container' => 'div', 'container_class' => 'responsive-menu-wrapper', 'theme_location'=>'main_menu') );

}


echo '</div>';

}

?>

<div class="navigation-wrapper">

<div class="navigation-container-wrapper container-wrapper">

<!-- Get Navigation -->

<?php
if( is_page_template('alternate-page.php') ){

wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'alternate-menu' ) );

}else{

wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'main_menu' ) );
}

?>



<!-- Get Search form -->

<?php if(get_option(THEME_SHORT_NAME.'_enable_top_search','enable') == 'enable'){?>

<div class="search-wrapper"><?php get_search_form(); ?></div>

<?php } ?>



<div class="clear"></div>

</div> <!-- navigation-container-wrapper -->

</div> <!-- navigation-wrapper -->

</div>


if do not work then please provide us error text or functions.php and alternate-page.php page code.
Please confirm that you have selected proper template before checking.


leajulia comments:

Hi Guys,


great, it worked. Thanks a bunch!

2014-03-27

Arnav Joy answers:

please try this


<div class="main-navigation-wrapper">

<?php

if( $gdl_is_responsive ){

echo '<div class="responsive-container-wrapper container-wrapper">';

dropdown_menu( array('dropdown_title' => '-- Main Menu --', 'indent_string' => '- ', 'indent_after' => '','container' => 'div', 'container_class' => 'responsive-menu-wrapper', 'theme_location'=>'main_menu') );

echo '</div>';

}

?>

<div class="navigation-wrapper">

<div class="navigation-container-wrapper container-wrapper">

<!-- Get Navigation -->

<?php
if( is_page_template('alternate-page.php') )
wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'alternate-menu' ) );
else
wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'main_menu' ) );
?>



<!-- Get Search form -->

<?php if(get_option(THEME_SHORT_NAME.'_enable_top_search','enable') == 'enable'){?>

<div class="search-wrapper"><?php get_search_form(); ?></div>

<?php } ?>



<div class="clear"></div>

</div> <!-- navigation-container-wrapper -->

</div> <!-- navigation-wrapper -->

</div>

2014-03-27

Hariprasad Vijayan answers:

Did you try it like this?


<!-- Navigation and Search Form -->





<div class="main-navigation-wrapper">

<?php

if ($gdl_is_responsive) {

echo '<div class="responsive-container-wrapper container-wrapper">';

dropdown_menu(array('dropdown_title' => '-- Main Menu --', 'indent_string' => '- ', 'indent_after' => '', 'container' => 'div', 'container_class' => 'responsive-menu-wrapper', 'theme_location' => 'main_menu'));

echo '</div>';

}
?>

<div class="navigation-wrapper">

<div class="navigation-container-wrapper container-wrapper">

<!-- Get Navigation -->

<?php
if ( is_page_template('alternate-page.php') ) {
wp_nav_menu(array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class' => 'sf-menu', 'theme_location' => 'alternate_menu'));
} else {
wp_nav_menu(array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class' => 'sf-menu', 'theme_location' => 'main_menu'));
}
?>


<!-- Get Search form -->

<?php if(get_option(THEME_SHORT_NAME.'_enable_top_search','enable') == 'enable'){?>

<div class="search-wrapper"><?php get_search_form(); ?></div>

<?php } ?>



<div class="clear"></div>

</div> <!-- navigation-container-wrapper -->

</div> <!-- navigation-wrapper -->

</div>