嗯,我的例子是基于Gioia已经提供的内容和Codex上的例子here.
还有一个提示,如果要坚持使用WordPress编写PHP,请避免使用速记WordPress\' best practices, 所以您总是想写出开头的PHP标记。
我想为第一个标记打破foreach,这样您就可以为剩余的标记创建一个无序列表,并希望能够更轻松地使用CSS进行样式设计。如果有人有更好的方法,请告诉我。以下是我所拥有的:
<?php 
$posttags = get_the_tags();
$count = 0;
if ( $posttags ) {
    foreach( $posttags as $post_tag ) { 
        $count++; //add to counter
        $tag_id = $post_tag->term_id; //get tag id so we can use it for a tag link
        if ( 1 == $count ) {
            echo \'<a href="\' . get_tag_link($tag_id) . \'" class="first-tag">\' . $post_tag->name . \'</a>\';
        } //end of first tag if statement 
        break;// break out of this for each so we can use a ul to separate the tags after the first
    } //end of for each ?>
    <ul class="remaining-tags">
        <?php foreach( $posttags as $remaining_tag ) { 
            $count++; //add to counter
            if ( 2 != $count ) { 
                echo \'<li><a href="\' . get_tag_link($tag_id) . \'">\' . $remaining_tag->name . \'</a></li>\';
            } // end of if statment for tags after first one
        } //end of for each ?>
    </ul>
<?php } //end of if $posttags ?>
 我在这里和这个缩进作斗争,如果你读起来有困难,请告诉我。希望能有点帮助。这也应该在循环中起作用。