获取 WordPress 分类法 slug 名称以用作 div 类

发布于 2024-10-13 03:47:35 字数 344 浏览 5 评论 0原文

我正在尝试使用他们的自定义分类法 slug 作为 div 类来标记我的帖子,以便可以过滤它们...

到目前为止,我显示了分类法名称,但我需要的是 slug,所以我有一个很好的空间-free-name,到目前为止我输出的名称如下:

<div class="box-item cocktails-box 
<?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'cocktail_type', '', ' ', '' ) );
echo $terms_as_text; ?>">

I'm trying to mark up my posts using their custom taxonomy slug as the div class so that they can be filtered...

So far what I have displays the taxonomy name but what I need is the slug so I have a nice-space-free-name, I have the below so far outputting the name:

<div class="box-item cocktails-box 
<?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'cocktail_type', '', ' ', '' ) );
echo $terms_as_text; ?>">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

所有深爱都是秘密 2024-10-20 03:47:35

尝试wp_get_post_terms()。它将返回一个对象数组,而不是回显逗号分隔的列表,对象参数之一是 slug。

看看:代码中的wp_get_post_terms

Try wp_get_post_terms(). It will return an array of objects instead of echoing a comma delimited list, one of the object parameters being the slug.

Check it out: wp_get_post_terms in the codex

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