如何在 wp_dropdown_pages 函数中回显分类标签?

问题描述 投票:0回答:1
php wordpress select menu taxonomy
1个回答
1
投票

您可以使用以下代码创建类别:

add_filter('list_pages', 'change_html', 10, 2);

function change_html($title, $page){
    if(!is_admin()){
        //To get category
        $category = wp_get_object_terms( $page->ID, 'category' );
        $category_name = $category[0]->name;

        //To get tag
        $tag = wp_get_post_tags($page->ID);
        $tag_name = $tag[0]->name;

        return $title.' ('.$category_name.')';
    }
    return $title;
    //If you want Tag name, you can have it by following line
    //return $title.' ('.$tag_name.')';
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.