我想在 single.php 中显示带有描述的单个帖子标签。我搜索了这个,最接近的解决方案如下。但是这段代码列出了博客的所有标签和描述。$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>'; } } }我只需要列出带有描述的帖子标签。(它应该排除没有描述的帖子标签。)例如:我们在数据库中有4500 多个标签。200 多个标签有描述。示例单个帖子上有7 个标签。其中只有4 个有描述。结果:我只需要在 single.php 中显示4 个标签。
1 回答
三国纷争
TA贡献1804条经验 获得超7个赞
你可以试试下面的代码,它可以在 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 关注
- 164 浏览
添加回答
举报
0/150
提交
取消