我试图通过id回显一个特定的标签。有相当多的标签列表,因此它应该只显示该标签,如果该帖子有该标签。
目前我正在使用此代码来回显标签:
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . '. ';
}
}
?>
但那个回声是帖子的所有标签。那么,如果该帖子中有一个来自ID列表的标签ID,我该如何通过id回显标签?
抱歉,我不能写评论,所以我必须在这里写下你的答案:
<?php
$tags_array = array(16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58);
$posttags = get_the_tags();
if ($posttags)
{
foreach($posttags as $tag)
{
if (in_array($tag->term_id, $tags_array))
{
echo $tag->name . ', ';
}
}
}
?>