我想在 single.php 中顯示帶有描述的單個(gè)帖子標(biāo)簽。我搜索了這個(gè),最接近的解決方案如下。但是這段代碼列出了博客的所有標(biāo)簽和描述。$tags = get_tags( array( 'hide_empty' => false ) );if ($tags) { foreach ($tags as $tag) { if ($tag->description) { echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>'; } } }我只需要列出帶有描述的帖子標(biāo)簽。(它應(yīng)該排除沒(méi)有描述的帖子標(biāo)簽。)例如:我們?cè)跀?shù)據(jù)庫(kù)中有4500 多個(gè)標(biāo)簽。200 多個(gè)標(biāo)簽有描述。示例單個(gè)帖子上有7 個(gè)標(biāo)簽。其中只有4 個(gè)有描述。結(jié)果:我只需要在 single.php 中顯示4 個(gè)標(biāo)簽。
1 回答

三國(guó)紛爭(zhēng)
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
你可以試試下面的代碼,它可以在 single.php 中工作
<?php
$tags = wp_get_post_tags(get_the_ID());
if ($tags) {
foreach ($tags as $tag) {
if ($tag->description) {
echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
}
}
}
?>
- 1 回答
- 0 關(guān)注
- 186 瀏覽
添加回答
舉報(bào)
0/150
提交
取消