Wordpress - List out tags on template files

2019-09-09 22:27发布

问题:

How do I list out all the tags to a template file?

I've looked at the wordpress documentation and found this..

<?php
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
           echo $tag->name . ' '; 
        }
    }
 ?>

However this doesn't output anything to my template.

Is there something that I am missing that i need to do on templates?

回答1:

Try this code

<?php
    $posttags  = get_terms( array(  'taxonomy' => 'post_tag') );

    if ($posttags ) {
        foreach($posttags  as $tag) {
            echo $tag->name . ' '; 
        }
    }
 ?>


标签: php wordpress