php - PHP if 语句中缺少 HTML 元素且格式不正确

标签 php html css wordpress custom-post-type

我在 wordpress 自定义帖子类型 (CPT) 中有此代码。尽管我做了所有尝试,但 span 标签中的 font awesome 元素不会显示并且 css 属性被遗漏

$memEmail = the_field('member_email');
if( !empty($memEmail)) { ?>
    echo                        
    '<a href="mailto:#"><span>
         <i class="fa fa-envelope-o"></i>'
         .$memEmail. '</span></a>';     
   <?php }

这是CSS

span {
    border-top: 1px dotted #fff;
    border-bottom: 1px dotted #fff;
    padding: 7px 0;
    font-family: 'Raleway';
}

下图显示了没有 if 语句的最终输出应该如何:

The final output was supposed to be this:

但是上面的代码在 if 语句中输出了这个:

enter image description here

最佳答案

您需要在 HTML 页面中引用 Font Awesome,或者如果您要发送电子邮件,则需要将其包含在电子邮件 HTML 中。您可以尝试添加此 CDN,尽管还有其他 CDN:

https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css

添加到 HTML 的代码是:

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

如果没有正确引用 Font Awesome,图标将不会显示。

关于php - PHP if 语句中缺少 HTML 元素且格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48368912/

相关文章:

php - fatal error : Class 'WP_Customize_Control' not found - WordPress

php - 如何使用 PHP5 逐字节读取/写入文件?

javascript - 如何使用 vanilla javascript 确定 <div> 是否可滚动?

html - Css - wordpress 中水平对齐期间的不可见边距

php - Laravel 5.4 Api 路线 401

javascript - 如何将 Wordpress phpshortcode 添加到 HTML 页面或自定义模板中?

javascript - 在某个时候停止滚动

html - CSS Cover 链接文字与图片

jquery - 为什么通过 AJAX 无限滚动加载的内容加载后高度测量不正确?

CSS 设置宽度以填充剩余区域的百分比