need help in using get_the_tag_list($ID) WordPress

后端 未结 2 679
盖世英雄少女心
盖世英雄少女心 2021-01-22 09:14

I am making a new WordPress template and I want to just get, in text format, the list of tags associated with a post. I am using

get_the_tag_list($id)

相关标签:
2条回答
  • 2021-01-22 09:25

    The template tag get_the_tags() returns an array of all of the tags associated with the post currently in-context within the Loop. You could traverse this array and generate a comma-separated list by hand.

    Here's an example of how you could do it using the implode and print_r functions:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach ($posttags as $tag) {
         $tagnames[count($tagnames)] = $tag->name;
      }
      $comma_separated_tagnames = implode(", ", $tagnames);
      print_r($comma_separated_tagnames);
    }
    ?>
    
    0 讨论(0)
  • 2021-01-22 09:44
    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    echo $tag->name . ','; 
    }
    }
    ?>
    

    Source: http://codex.wordpress.org/Template_Tags/get_the_tags

    0 讨论(0)
提交回复
热议问题