在 wordpress 中使用特定标签在页面上显示文本

Display text on page with specific tag in wordpress

我想在 wordpress 中显示带有特定标签的文本。

例如:我有 2 个标签:汽车和船,以及 2 个文本:"I have car and i want one bike"、"I have boat and i am happy"

当标签存在时,我想在 header 特定文本中显示。

我尝试使用 tem exist in header.php 但在所有页面中显示文本,而不仅仅是在存在标签的页面中。

例如:

 <?php
$boat = term_exists('boat', 'post_tag');
if ($boat !== 0 && $boat !== null) {
  echo "I have boat and i am happy!";
}
    ?>

如果你只有两个标签就可以了。

<?php 
if (is_tag( 'boat' )) {
    echo "I have boat and i am happy!";
} elseif (is_tag('car'))   {
    echo "I have a car";
}
?>