如何在不显示旁边的文本时隐藏字体真棒图标?
How to hide the font awesome icon when the text next to it is not displayed?
我正在尝试在我的 Wordpress post 的一些元数据旁边显示很棒的字体图标。一个示例是在以下代码中的文本 'tag' 之前使用标记图标:
<i class="fa fa-tags" aria-hidden="true"></i> <?php eco($tag); ?>
问题是我需要在不显示标签名称时隐藏 FA 图标。我的意思是,如果用户决定不写任何标签,图标就会保留在那里。
关于在没有为 post 编写标签时如何摆脱图标的任何想法?
完整代码为:
<div class="meta-tags">
<?php $tag = get_the_tag_list( __('tags: ', 'themename'),', ' );
<i class="fa fa-tags" aria-hidden="true"> </i> <?php echo ($tag); ?>
</div>
谢谢
也许你可以用 php
做这样的事情
<?php if ($tag){ echo '<i class="fa fa-tags" aria-hidden="true">';} ?>
我更喜欢使用 the empty
function。您可以合并所有 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"> </i>' . $tag;
?>
</div>
您还可以在 wp-includes 文件夹中编辑类别-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>
我正在尝试在我的 Wordpress post 的一些元数据旁边显示很棒的字体图标。一个示例是在以下代码中的文本 'tag' 之前使用标记图标:
<i class="fa fa-tags" aria-hidden="true"></i> <?php eco($tag); ?>
问题是我需要在不显示标签名称时隐藏 FA 图标。我的意思是,如果用户决定不写任何标签,图标就会保留在那里。
关于在没有为 post 编写标签时如何摆脱图标的任何想法?
完整代码为:
<div class="meta-tags">
<?php $tag = get_the_tag_list( __('tags: ', 'themename'),', ' );
<i class="fa fa-tags" aria-hidden="true"> </i> <?php echo ($tag); ?>
</div>
谢谢
也许你可以用 php
做这样的事情<?php if ($tag){ echo '<i class="fa fa-tags" aria-hidden="true">';} ?>
我更喜欢使用 the empty
function。您可以合并所有 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"> </i>' . $tag;
?>
</div>
您还可以在 wp-includes 文件夹中编辑类别-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>