【问题标题】:ACF Wordpress styling custom fieldsACF Wordpress 样式自定义字段
【发布时间】: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) ):之后添加?&gt;关闭它,然后在img标签后添加&lt;?php重新启动它。
  • 好的。我认为还有其他“更漂亮”的方式。
  • 您也可以只回显图像:echo '&lt;img src="' . $image['url'] . '" alt="' . $image['alt'] . '" /&gt;。只是偏好问题。

标签: php html wordpress twitter-bootstrap advanced-custom-fields


【解决方案1】:

我建议你这样做:

<?php if (have_rows('repeater')): ?>
    <?php while (have_rows('repeater')): the_row(); ?>

    <?php
    $variable = get_sub_field('variable');
    ?>

    <div class="repeater-item">
        <div class="variable-item">
            <?php echo $variable; ?>
        </div>
    </div>
    <?php endwhile; ?>
<?php endif; ?>

在这之后你要做的就是为 div class="variable-item" 中的所有内容设置样式,然后你可以在其中设置任何内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2021-07-30
    • 2018-08-15
    • 2019-04-11
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多