获取 WordPress 分类法 slug 名称以用作 div 类
我正在尝试使用他们的自定义分类法 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
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