Wordpress - List out tags on template files

2019-09-09 21:55发布

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?

标签: php wordpress
1条回答
叼着烟拽天下
2楼-- · 2019-09-09 22:50

Try this code

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

    if ($posttags ) {
        foreach($posttags  as $tag) {
            echo $tag->name . ' '; 
        }
    }
 ?>
查看更多
登录 后发表回答