Using parent slug variable to display proper submenu not working properly

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:

Read More

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;
}

Related posts