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.

There are three submenus I have which display based on where you are in the site using the "the_parent_slug()" function. (personal-liability, life-and-health, and business) So when I use the search box at the top of the page and search for the following terms, the submenu shows up. It seems if those words are in the URL at all, it triggers the submenu to load. They are "Personal Liability" and "Life". Searching for "Life and Health" does not pop up the submenu surprisingly. Can anyone provide assistance in this matter.

Code and link to follow:

http://s168249.gridserver.com/

<?php $parent_slug = the_parent_slug(); ?>

<?php if(is_page('personal-liability') || $parent_slug == 'personal-liability') { ?>
    <div id="secondary_menu" class="personal-menu">
        <div id="secondary_menu_inside">
            <?php wp_nav_menu( array( 'container_class' => 'menu-header3', 'theme_location' => 'personal' ) ); ?>
        </div>
    </div>
<?php } else if(is_page('life-and-health') || $parent_slug == 'life-and-health') { ?>
    <div id="secondary_menu" class="life-and-health-menu">
        <div id="secondary_menu_inside">
            <?php wp_nav_menu( array( 'container_class' => 'menu-header3', 'theme_location' => 'life-and-health' ) ); ?>
        </div>
    </div>
<?php } else if(is_page('business') || $parent_slug == 'business') { ?>
    <div id="secondary_menu" class="commercial-menu">
        <div id="secondary_menu_inside">
            <h3 class="business_menu_header1">Areas of Expertise</h3><h3 class="business_menu_header2">Policy Types</h3>
            <?php wp_nav_menu( array( 'container_class' => 'menu-header3 business', 'theme_location' => 'business' ) ); ?>
            <?php wp_nav_menu( array( 'container_class' => 'menu-header3 business2', 'theme_location' => 'business2' ) ); ?>
        </div>
    </div>
<?php } else if(is_page('claims')) { ?>
    <div id="secondary_menu" class="claims-menu">
    </div>
<?php } ?>

Below is the custom the_parent_slug() function I added during the course of development:

function the_parent_slug() {
    global $post;
    if($post->post_parent == 0) {
        return '';
    }

    $post_data = get_post($post->post_parent);
    return $post_data->post_name;
}
share|improve this question
    
What is the_parent_slug()? Where is that defined? Is that new is 3.6.1 and I've missed it? –  s_ha_dum Sep 27 '13 at 15:04
    
Forgot I added that functionality along the way. Basically it checks if it is a child or a parent menu element and sends back the appropriate data. I've echoed what comes out from this and it's the correct parent slug string. Not sure why it's giving false positives. –  Dave Rottino Sep 27 '13 at 15:20
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.