WordPress 将分类显示为下拉菜单

发布于 2025-01-04 16:21:34 字数 563 浏览 2 评论 0原文

我建立了一个分层分类法,在管理员中显示可用香水的主列表。创建页面时,您可以选中该特定页面可用的香水。我将此代码用于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2025-01-11 16:21:34

您需要类似 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文