Welcome! To use this support forum, please Login or Join Today!

   

[SOLVED] Different Menus for Different Pages

{name}
Rank

Total Posts: 23

Joined 2015-08-06

PM

 

Hi Casey,

This topic was also referenced in the Synapse forum here.

I’m familiar with basic WordPress conditionals and have used these successfully in the past when applying different *Top Bar* menus on, say, the main pages vs blog posts. This time, I’ve tried to do the same with the wp_nav_menu and have run into a problem.

I didn’t anticipate the $menu_placement variable and wasn’t sure how to write around it. Instead, I simply deleted it and hardcoded the menu class. Alas, the approaches fails and crashes the site. Here’s the child theme’s functions.php snippet and a hastebin link if it’s easier to read:

<?php

/*-----------------------------------------------------------------------------------*/
// Main Navigation Conditionals Based On City Pages
/*-----------------------------------------------------------------------------------*/

function st_main_nav() {

 
echo '<div id="menu" class="below">';
 echo 
'<div class="container">';
 echo 
'<div class="sixteen columns">';

 
// Dallas Menu
 
if (is_page( array( 111114116126128133 ) )  {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '3''theme_location' => 'primary''menu_id' => 'nav3'));
 
// Austin Menu
 
elseif (is_page( array( 111016121833 ) )  {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '4''theme_location' => 'primary''menu_id' => 'nav4'));
 
// Houston Menu (default)
 
else {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '2''theme_location' => 'primary''menu_id' => 'nav'));
 
}
 
echo '</div><!--/.columns row-->';
 echo 
'</div><!--/.container-->';
 echo 
'<div class="clear"></div>';
 echo 
'</div><!--/#menu-->';
}
add_action
'st_header''st_main_nav'3);

?> 

Do you have any idea why this fails and, ultimately, crashes the site? Any help would be greatly appreciated.

{name}
Rank

Total Posts: 23

Joined 2015-08-06

PM

 

Sorry, Casey! Yikes… just realized my error. Correct code below for anyone interested.

One question about the $menu_placement variable: How would you include that (i.e., below menu vs right menu) in this particular snippet? I guess it’s easy enough to hardcode the menu class, but I’m just curious if keeping that $menu_placement conditional makes sense or even matters with the below approach.

Please let me know whenever you have time. Cheers!

<?php

/*-----------------------------------------------------------------------------------*/
// Main Navigation Conditionals Based On City Pages
/*-----------------------------------------------------------------------------------*/

function st_main_nav() {

 
echo '<div id="menu" class="below">';
 echo 
'<div class="container">';
 echo 
'<div class="sixteen columns">';

 
// Dallas Menu
 
if (is_page( array( 111114116126128133 ) ) ) {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '3''theme_location' => 'primary''menu_id' => 'nav3'));
 
// Austin Menu
 
elseif (is_page( array( 111016121833 ) ) ) {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '4''theme_location' => 'primary''menu_id' => 'nav4'));
 
// Houston Menu (default)
 
else {
 wp_nav_menu
( array( 'container_class' => 'menu-header''menu' => '2''theme_location' => 'primary''menu_id' => 'nav'));
 
}
 
echo '</div><!--/.columns row-->';
 echo 
'</div><!--/.container-->';
 echo 
'<div class="clear"></div>';
 echo 
'</div><!--/#menu-->';
}
add_action
'st_header''st_main_nav'3);

?>