我试图显示字体可怕的图标旁边的一些元数据为我的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"> </i> <?php echo ($tag); ?>
</div>谢谢
发布于 2016-06-20 10:15:16
我更喜欢使用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>发布于 2016-06-20 10:00:42
也许您可以使用php进行类似的操作。
<?php if ($tag){ echo '<i class="fa fa-tags" aria-hidden="true">';} ?>发布于 2016-09-29 18:01:40
还可以在wp-include文件夹中编辑类别-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>https://stackoverflow.com/questions/37919095
复制相似问题