【问题标题】:Wordpress, how to get the tag slug from tag name in a post page?Wordpress,如何从帖子页面中的标签名称中获取标签 slug?
【发布时间】:2016-01-08 05:55:47
【问题描述】:

在单个帖子中,如何获取用于该特定帖子的标签标签和标签 ID。

例如;我有一个帖子“Hello World!”标记在“我的帖子”中。如何在“Hello World!”中获取“我的帖子”的内容。发布页面(即:single.php 文件)。

【问题讨论】:

  • 试试 get_term_by("My Post"),var_dump 它,你可能会有一些想法。

标签: wordpress wordpress-theming


【解决方案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

【讨论】:

  • @DurgaPrasadKundu,我想现在你可以了。 :-)
猜你喜欢
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2015-10-27
  • 2023-04-04
  • 2018-04-16
相关资源
最近更新 更多