Wordpress,如何从 post 页面中的标签名称获取标签 slug?
Wordpress, how to get the tag slug from tag name in a post page?
在单个 post 中,如何获取用于该特定 post 的标签的标签别名和标签 ID。
例如;我在 "My Post" 中标记了 post "Hello World!"。如何在 "Hello World!" post 页面(即 single.php 文件)中获取 slug "my-post"。
$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
在单个 post 中,如何获取用于该特定 post 的标签的标签别名和标签 ID。
例如;我在 "My Post" 中标记了 post "Hello World!"。如何在 "Hello World!" post 页面(即 single.php 文件)中获取 slug "my-post"。
$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