Custom Menus, Widgets & Conditional Statements

I’m employing custom widgets for my client because it’s easy and they have several menus they need to create specific to site sections. I then want to allow them to add to the custom menu dynamically using widgets (I create the spaces needed for the widget and they drag and drop the menus into that widget bucket).

I tried using the following code but when the left nav sidebar is supposed to load, the page stops loading.

Read More
if (is_page( 'sport-fitness' ) || '269' == $post->post_parent){
//menu for Sport & Fitness pages

<div id="seventh" class="widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-7' ); ?>
    </div><!-- #second .widget-area -->

}elseif(is_page( 'eat-smart' ) || '118' == $post->post_parent){
//menu for Eat Smart pages

<div id="eighth" class="widget-area" role="complementary">
    <?php dynamic_sidebar( 'sidebar-8' ); ?>
</div><!-- #second .widget-area -->

}else{
//default menu

}

The custom menus need to show up on all child pages (but not the parent page because that uses a different layout). What am I doing wrong with the above?

I got this to work:

if (is_page( 'sport-fitness' ) || '269' == $post->post_parent){
//menu for Sport & Fitness pages

wp_nav_menu( array('menu' => 'sport-fitness' ));

}elseif(is_page( 'eat-smart' ) || '118' == $post->post_parent){
//menu for Eat Smart pages

wp_nav_menu( array('menu' => 'eat-smart' ));

}else{
//default menu

} 

But then I’m stuck without the headers that the widgets provide (which they want). For example:
SPORT & FITNESS

  • Home
  • Link 1
  • Link 2
  • Link 3

Help would be greatly appreciated. I’ve been trying to figure this out for a couple days now and it’s a blocker to finishing their site.

TIA!

Related posts

Leave a Reply

1 comment

  1. if you want to show the menus only on child pages then you need to change your conditional statement:

    global $post;
    //only on children of 269
    if ('269' == $post->post_parent){
    //menu for Sport & Fitness pages
    ?>
    <div id="seventh" class="widget-area" role="complementary">
            <?php dynamic_sidebar( 'sidebar-7' ); ?>
        </div><!-- #second .widget-area -->
    <?php
    //only on children of 118
    }elseif( '118' == $post->post_parent){
    //menu for Eat Smart pages
    ?>
    <div id="eighth" class="widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-8' ); ?>
    </div><!-- #second .widget-area -->
    <?php
    //everything else including parent pages
    }else{
    //default menu
    
    }