简体   繁体   English

如何在没有显示旁边的文本时隐藏字体真棒图标?

[英]How to hide the font awesome icon when the text next to it is not displayed?

I am trying to show the font awesome icons next to some metadata for my Wordpress posts. 我试图在我的Wordpress帖子的某些元数据旁边显示字体真棒图标。 An example is the use of the tag icon before the text 'tag' in the following code: 一个例子是在以下代码中使用文本'tag'之前的标记图标:

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

The problem is I need to hide the FA icon when the tag name is not shown. 问题是我需要在标签名称未显示时隐藏FA图标。 I mean if the user decides not to write any tags, the icon sticks there. 我的意思是如果用户决定不写任何标签,那么图标就会粘在那里。

Any ideas on how I can get rid of the icon when no tags are written for a post? 关于如何为帖子编写标签时如何摆脱图标的任何想法?

The complete code is: 完整的代码是:

<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>

Thanks 谢谢

也许你可以用php做这样的事情

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

I prefer to use the empty function . 我更喜欢使用empty函数 And you can merge all pieces of your php-code. 你可以合并你的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>

You can also edit category-template.php within the wp-includes folder 您还可以在wp-includes文件夹中编辑category-template.php

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

and just call the_tags 并只需调用the_tags

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM