^ Back to top

WordPress函数:get_the_term_list

一、get_the_term_list函数功能描述:

Returns an HTML string of taxonomy terms associated with a post and given taxonomy.Terms are linked to their respective term listing pages.

二、get_the_term_list函数语法:

<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) >

三、get_the_term_list函数参数:

1、$id

(int) (required) Post ID

Default: None

2、$taxonomy

(string) (required) Name of taxonomy

Default: None

3、$before

(string) (optional) Leading text

Default: empty string

4、$sep

(string) (optional) String to separate tags

Default: empty string

5、$after

(string) (optional) Trailing text

Default: empty string

四、get_the_term_list函数返回数据:

(string)

HTML string of taxonomy terms.

(bool)

false if the post does not have any associated terms.

五、get_the_term_list函数用法举例:

1、基本用法

循环内调用Used inside the loop this outputs the terms from the people taxonomy for a specific post.

<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' ); ?>

会输出类似下面的结构:

People: <a href="person1">Person 1</a>, <a href="person2">Person 2</a>, ...

2、高级用法

循环内调用Used inside the loop this outputs the terms from the styles taxonomy for a specific post as an (x)html list.

echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );

会输出类似下面的结构,可以自定义css

<ul class="styles">
    <li><a href="person1">Style 1</a></li> 
    <li><a href="person2">Style 2</a></li>
</ul>

陌陌评论 2

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. 商学院
    看不懂,不过看得出很用心的写,支持下po主回复
  2. 龙笑天
    首页大变样啊~ :mrgreen:回复

站内搜索

其他人正在搜