如何在多个页面中显示 ACF 插件字段
How to display ACF plugin fields in several pages
我在ACF插件中创建了一组字段,这组字段只属于一个页面(例如page-contacts.php),但是我想在多个页面上显示这组字段(例如page -main.php).这是页面上的转发器字段循环-contact.php。
<?php if( have_rows('slider') ): ?>
<div id = "events-slider">
<?php while( have_rows('slider') ): the_row(); ?>
<div class = "events-slider__slide">
<img src="<?php the_sub_field('image'); ?>" alt>
</div>
<?php endwhile;?>
</div>
<?php endif;?>
如何在页面-main.php上使用这个循环?
要从另一个页面获取字段,您可以添加页面 ID 作为第二个参数:
have_rows($field_name, $post_id);
然后您只需要页面的 post ID,其中包含正确的内容 -
祝你好运!
我在ACF插件中创建了一组字段,这组字段只属于一个页面(例如page-contacts.php),但是我想在多个页面上显示这组字段(例如page -main.php).这是页面上的转发器字段循环-contact.php。
<?php if( have_rows('slider') ): ?>
<div id = "events-slider">
<?php while( have_rows('slider') ): the_row(); ?>
<div class = "events-slider__slide">
<img src="<?php the_sub_field('image'); ?>" alt>
</div>
<?php endwhile;?>
</div>
<?php endif;?>
如何在页面-main.php上使用这个循环?
要从另一个页面获取字段,您可以添加页面 ID 作为第二个参数:
have_rows($field_name, $post_id);
然后您只需要页面的 post ID,其中包含正确的内容 -
祝你好运!