Php Wordpress动态导航功能,用于突出显示单个帖子选项卡

Php Wordpress动态导航功能,用于突出显示单个帖子选项卡,php,wordpress,Php,Wordpress,我试图写一个功能,我可以在我的WordPress主题中重复使用,这将允许我建立强大的动态导航菜单。以下是我到目前为止的情况: 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

我试图写一个功能,我可以在我的WordPress主题中重复使用,这将允许我建立强大的动态导航菜单。以下是我到目前为止的情况:

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>";
}
这段代码的工作原理和预期的一样,只是我不能为一篇博客文章启用它,因为页面名称是动态的


我知道WordPress功能是单一的,我在以前的导航菜单中使用它来实现这一功能,但我找不到一种方法将它集成到这个功能中。

我可以看出你是怎么做的, 在is_页面的if语句中

你能用,

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

    if(is_page($name)){
            echo " class='current_page_item'>";
    }else **if(is_single($name)){
            echo " class='current_page_item'>";**
    }else{
            echo ">";
    }
    echo  "<a href=$href>$tabname</a>";
    echo  "</li>";
}
我自己没试过