WordPress 将分类显示为下拉菜单
我建立了一个分层分类法,在管理员中显示可用香水的主列表。创建页面时,您可以选中该特定页面可用的香水。我将此代码用于functions.php,它似乎在管理中工作:
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'scents',
'page',
array( 'hierarchical' => true,
'label' => 'Scents',
'query_var' => true,
'rewrite' => true ) );
}
现在我需要输出选中的项目,以便它们以下拉菜单的形式显示在页面上。
问题是它输出所有页面上已勾选的所有气味。我只需要它输出您所在页面上已选中的内容。
这是我使用的代码:
<?php wp_dropdown_categories('taxonomy=scents'); ?>
如何编辑此代码,使其仅显示我所在页面的香水?谢谢。
I've built a hierarchical taxonomy that displays a master list of available fragrances in the admin. When you create a page, you checkmark the fragrances that are available for that particular page. I used this code to functions.php and it seems to work in the admin:
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'scents',
'page',
array( 'hierarchical' => true,
'label' => 'Scents',
'query_var' => true,
'rewrite' => true ) );
}
Now I need to output the checkmarked items so they display on the page in the form of a drop down menu.
The problem is that it outputs ALL scents that have been check marked across ALL pages. I just need it to output the ones that have been check marked on the page you're on.
Here's the code I used:
<?php wp_dropdown_categories('taxonomy=scents'); ?>
How do I edit this so that it only shows the fragrances for the page I'm on? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要类似
wp_get_object_terms($post->ID, 'scents')
查看文档:http://codex.wordpress.org/Function_Reference/wp_get_object_terms
You need something like
wp_get_object_terms($post->ID, 'scents')
Chek out the docs at: http://codex.wordpress.org/Function_Reference/wp_get_object_terms