Wordpress,如何从帖子页面中的标签名称获取标签slug?

时间:2016-01-08 05:55:48

标签: wordpress wordpress-theming

在一篇文章中,如何获得标签slug&用于该特定帖子的标签的标签ID。

例如;我有一个帖子" Hello World!"标记在"我的帖子"。如何获得slug" my-post"在" Hello World!"帖子页面(即; single.php文件)。

1 个答案:

答案 0 :(得分:1)

$terms = get_the_terms( $post->ID, 'post_tag' );
if ( !empty( $terms ) ){
    // get the first term
    $term = array_shift( $terms );
    echo $term->slug;
}

参考:https://wordpress.stackexchange.com/questions/130947/get-term-slug-of-current-post