如何在 wp_dropdown_pages 函数中回显分类标签?
How to echo taxonomy tags in the wp_dropdown_pages function?
对于我的 Wordpress 博客,我一直在试验 wp_dropdown_pages 函数。使用此代码
<form class="pagemenu" action="<?php bloginfo('url'); ?>" method="get">
<?php
$select = wp_dropdown_pages(
array(
'show_option_none' => 'Choisissez une autre liste de vocabulaire.',
'echo' => 0
)
);
echo str_replace('<select ', '<select onchange="this.form.submit()" ', $select);
?>
</form>
我可以呈现包含博客所有页面的下拉菜单。但我想知道是否可以在页面标题前面回显页面的特定类别。在我的博客中,每个页面都分配了一个特定的类别标签,具有语义功能,如果这个标签也呈现在菜单中就好了。
我已经研究这个问题几个小时了,但找不到答案。
感谢您的任何建议或建议。
您可以使用以下代码创建类别:
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.')';
}
对于我的 Wordpress 博客,我一直在试验 wp_dropdown_pages 函数。使用此代码
<form class="pagemenu" action="<?php bloginfo('url'); ?>" method="get">
<?php
$select = wp_dropdown_pages(
array(
'show_option_none' => 'Choisissez une autre liste de vocabulaire.',
'echo' => 0
)
);
echo str_replace('<select ', '<select onchange="this.form.submit()" ', $select);
?>
</form>
我可以呈现包含博客所有页面的下拉菜单。但我想知道是否可以在页面标题前面回显页面的特定类别。在我的博客中,每个页面都分配了一个特定的类别标签,具有语义功能,如果这个标签也呈现在菜单中就好了。
我已经研究这个问题几个小时了,但找不到答案。
感谢您的任何建议或建议。
您可以使用以下代码创建类别:
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.')';
}