当未显示旁边的文本时,如何隐藏字体真棒图标



我试图在我的WordPress帖子的某个元数据旁边显示字体很棒的图标。一个示例是在以下代码中的文本"标签"之前使用标记图标:

<i class="fa fa-tags" aria-hidden="true"></i> <?php eco($tag); ?>

问题是,当未显示标签名称时,我需要隐藏FA图标。我的意思是,如果用户决定不编写任何标签,则图标会贴在那里。

当没有为帖子编写标签时,我如何摆脱图标的任何想法?

完整的代码是:

<div class="meta-tags">
   <?php $tag = get_the_tag_list( __('tags: ', 'themename'),', ' );
   <i class="fa fa-tags" aria-hidden="true">&nbsp;</i> <?php echo ($tag); ?>
</div>

谢谢

我更喜欢使用empty函数。您可以合并PHP代码的所有部分。

<div class="meta-tags">
   <?php 
     $tag = get_the_tag_list( __('tags: ', 'themename'),', ' );
     if ( !empty($tag) ) echo '<i class="fa fa-tags" aria-hidden="true">&nbsp;</i>' . $tag; 
   ?>
</div>

也许您可以使用php

做这样的事情
<?php if ($tag){ echo '<i class="fa fa-tags" aria-hidden="true">';} ?>

您还可以在wp-confludes文件夹中编辑category-template.php

function the_tags( $before = null, $sep = ' ', $after = '' ) {
    if ( null === $before )
    $before = __('<i class="fa fa-tags" aria-hidden="true">');
}

只需致电the_tags

<div class="meta-tags">
    <?php the_tags(); ?>
</div>

最新更新