Wordpress dynamic navigation function for highlighting single post tabs

Posted by user269959 on Stack Overflow See other posts from Stack Overflow or by user269959
Published on 2010-03-13T00:13:10Z Indexed on 2010/03/13 0:17 UTC
Read the original article Hit count: 498

Filed under:

I am trying to write a function that i can reuse in my wordpress themes that will allow me to build robust dynamic navigation menus. Here is what i have so far:

function tab_maker($page_name, $href, $tabname) {

    //opens <li> tag to allow active class to be inserted if tab is on proper page
    echo "<li";
    //checks that we are on current page and highlights tab as active if so
    if(is_page($page_name)){
        echo " class='current_page_item'>";
    }

    //closes <li> tab if not active
    else {
        echo ">";
    }
    //inserts the link as $href and the name of the tab to appear as $tabname then closes <li>
    echo  "<a href=$href>$tabname</a>";
    echo  "</li>";

}

This code works as expected except i cant enable it to highlight for a single blog post as the page names are dynamic. I know about the wordpress function is_single() which ive used to implement this feature in previous nav menus but i cant find a way to integrate it into this function. appreciate any help!

© Stack Overflow or respective owner

Related posts about Wordpress