【发布时间】:2013-10-23 07:51:03
【问题描述】:
我有以下问题。我正在使用 Wordpress 的高级自定义字段为帖子创建字幕字段。我喜欢给这个副标题一些样式,但是我在 IF 语句中的 HTML 代码没有显示在页面上。 $subtitle 会显示。
<?php $subtitle = the_field('subtitle'); ?>
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
我花了几个小时寻找类似的问题,但找不到任何解决方案。所以这可能是我的菜鸟错误。
解决方案
<?php $subtitle = get_field('subtitle'); ?>
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
将 the_field() 更改为 get_field()。向 Aditya Vikas 致敬!
【问题讨论】:
标签: php wordpress if-statement