WordPress 自定义分类法 - get_the_terms_list();
我有一个名为“艺术家”的自定义分类法。我希望能够按如下方式显示艺术家:
[Main Artist / First in Array] ft. [Second Artists], [Third Artist] & [Last Artist]
我当前用于显示“艺术家”的代码是:
<?php $artists_links = get_the_term_list( $track->ID, 'artists', '', ' ', '' );
$artists_withoutlinks = strip_tags( $artists_links );
echo $artists_withoutlinks ?>
那么有人可以帮助解决这个问题吗?总之,我想要做的就是:
- 将第一个术语后面的分隔符更改为“ft”。
- 将最后一项之前的分隔符更改为“&”
显然,我希望将数据库调用保持在最低限度,并使查询尽可能快,非常感谢任何帮助。
I've got a custom taxonomy called "Artists". I'd like to be able to display the artists as follows:
[Main Artist / First in Array] ft. [Second Artists], [Third Artist] & [Last Artist]
The code I'm currently using to display the "Artist" is:
<?php $artists_links = get_the_term_list( $track->ID, 'artists', '', ' ', '' );
$artists_withoutlinks = strip_tags( $artists_links );
echo $artists_withoutlinks ?>
So would anyone be able to help with this? In summary all I want to be able to do is:
- Change the separator after the first term to "ft."
- Change the separator before the last term to "&"
Obviously I want to keep database calls to a minimum, and make the query as fast as possible, any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
get_the_terms()
而不是get_the_term_list()
。后者将术语提取到字符串中,而第一个创建术语数组。仍然只有一个查询。之后从数组创建字符串:Use
get_the_terms()
instead ofget_the_term_list()
. While the latter fetches the terms into a string, the first creates an array of terms. Still only one query. Create the string from the array afterwards: