Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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!

share|improve this question
    
I'll later take a look. The idea of "Widgets inside Nav Menus" is imo a kool one. +1. –  kaiser Aug 5 '11 at 11:42
1  
In the first example above you're missing ?> and <?php which should surround the HTML. –  Chris Carson Aug 5 '11 at 11:43
    
And try replacing || with &&. The first means OR, the second AND. –  kaiser Aug 5 '11 at 12:00
    
@Chris - could you expand on that? I'm not sure if you mean there should be additional opening & closing php tags to what would normally be there. –  Justice Is Cheap Aug 8 '11 at 20:25
    
In your example you went directly from PHP code into HTML and back again, without closing/opening PHP tags. Given that you said "the page stops loading" I thought that that was a good place to start debugging. –  Chris Carson Aug 8 '11 at 21:29

1 Answer 1

up vote 1 down vote accepted

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

}
share|improve this answer
    
I'll give this a try tomorrow Bainternet. Thanks. –  Justice Is Cheap Aug 8 '11 at 20:26
    
Just wanted to let you know, it works a treat! –  Justice Is Cheap Aug 24 '11 at 16:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.