【发布时间】:2017-02-01 12:29:30
【问题描述】:
我在为 .php 文件中的 ACF 的每个字段设置样式时遇到问题。
<?php the_field('service_section_title'); ?>
<?php the_field('service_section_description'); ?>
<a href="<?php the_field('service_section_button_link'); ?>">Learn more</a>
<?php if( have_rows('services') ):
while ( have_rows('services') ) : the_row();
$image = get_field('service_icon'); if( !empty($image) ):
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
get_field('service_title');
get_field('service_description');
endwhile; else : endif; ?>
我应该如何用 HTML 来包装我的
get_field('service_title');
get_field('service_description');
和图像字段;
例如:
<p class="text-faded">?php get_field('service_description');?>
</p>
如何正确的用html包裹php(不要用php打断php代码再打断)
【问题讨论】:
-
在
$image = get_field('service_icon'); if( !empty($image) ):之后添加?>关闭它,然后在img标签后添加<?php重新启动它。 -
好的。我认为还有其他“更漂亮”的方式。
-
您也可以只回显图像:
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] . '" />。只是偏好问题。
标签: php html wordpress twitter-bootstrap advanced-custom-fields