【发布时间】:2013-07-14 21:50:45
【问题描述】:
我想知道如何让#tag-container 仅在有标签时显示。我该怎么做呢?我在想有一些 if 和 else 语句,但我不知道如何正确编写它...
<div class="tag-container">
<p><?php the_tags(); ?></p>
</div>
【问题讨论】:
标签: php wordpress if-statement tags hide
我想知道如何让#tag-container 仅在有标签时显示。我该怎么做呢?我在想有一些 if 和 else 语句,但我不知道如何正确编写它...
<div class="tag-container">
<p><?php the_tags(); ?></p>
</div>
【问题讨论】:
标签: php wordpress if-statement tags hide
除了其他答案之外,我会将呈现的标签存储在一个变量中,以免两次调用同一个函数。
<?php $tags = get_the_tag_list( __('Tags: '), ', ' ); ?>
<?php if( !empty( $tags ) ) : ?>
<div class="tag-container">
<p><?php echo $tags; ?></p>
</div>
<?php endif; ?>
【讨论】:
Array 显示为值:) 类似于'<a href="...">'.implode('</a>, <a href="...">', $tags) . '</a>'
<?php
if( get_the_tags() ){
echo '<div class="tag-container"><p>';
the_tags();
echo '</p></div>';
}
【讨论】:
<?php if (!empty(get_the_tags())) : ?>
<div class="tag-container">
<p><?php the_tags(); ?></p>
</div>
<?php endif; ?>
【讨论】: