在使用bootstrap框架時,我們想要用按鈕或者徽章的樣式顯示文章標籤,可以使用如下代碼:
<?php
// 顯示標籤
$posttags = get_the_tags();
if ( $posttags ) {
echo '<div class="post-tags mb-3">標籤:';
foreach( $posttags as $tag ) {
echo '<a href="' . get_tag_link( $tag->term_id ) . '" class="badge badge-pill badge-success mr-3">' . $tag->name . '</a>';
}
echo '</div>';
}
?>