WordPress模板标签get_the_tags用于获取标签信息,包括标签ID、别名、名称、描述等。get_the_tags()函数需要用在The Loop主循环中,如果在主循环之外使用,需要传递文章ID。
get_the_tags( int $id = 0 )
函数参数
$id
整数型,默认值:当前文章ID
指定文章ID,将返回该文章的标签信息。
函数返回值
Array ( [0] => WP_Term Object ( [term_id] => 27 [name] => CDN [slug] => cdn [term_group] => 0 [term_taxonomy_id] => 27 [taxonomy] => post_tag [description] => PHP学习网。 [parent] => 0 [count] => 11 [filter] => raw ) )
使用示例
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '标签ID:' . $tag->term_id;
echo '
标签名称:' . $tag->name;
echo '
标签描述:' . $tag->description;
}
}
get_the_tags()函数位于:wp-includes/category-template.php













![[开源推荐] PHP DFA算法实现敏感词过滤包 php-dfa-sensitive](https://www.viphper.com/wp-content/uploads/2022/11/0f78983556550e6-240x180.png)


![[开源推荐] PHP版本田字格笔顺字帖生成器](https://www.viphper.com/wp-content/uploads/2022/11/2a6a84e9e44441a-240x180.png)

