在php中简洁地显示文本,如何制作


Display text corectly in php, how make?

我有这段代码,但不能正常工作。

当不存在has_tag时,我想显示标题1。当存在hst_tag car时,我只想显示标题2,当存在has_tag boat时,我想只显示标题3。

echo '<h1>Title 1</h1>';
if (has_tag( 'car' )) {
    echo '<h1>Title 2</h1>';
} elseif (has_tag('boat'))   {
    echo "Title 3";
}

嗯。。。

if (has_tag( 'car' )) {
    echo '<h1>Title 2</h1>';
} elseif (has_tag('boat'))   {
    echo "Title 3";
} else {
    echo '<h1>Title 1</h1>'; // No tag or any other tag besides car and boat
}

如果你必须确保没有标签:

if (has_tag( 'car' )) {
    echo '<h1>Title 2</h1>';
} elseif (has_tag('boat'))   {
    echo "Title 3";
} elseif (!has_tag()) {
    echo '<h1>Title 1</h1>'; // No tag
}