Using ACF (Advanced Custom Fields), I set up a field (slides
) with two subfields (title
) and (slide
). In my header.php
file, I have this code which outputs a list of the title
subfield.
// header.php //
<nav id="site-navigation" class="main-navigation" role="navigation">
<?php $frontpage_id = get_option('page_on_front'); ?>
<?php if ( is_singular() && have_rows('slides', $frontpage_id) ): ?>
<ul>
<?php while ( have_rows('slides', $frontpage_id) ) : the_row(); ?>
<li class="group"><a href="#"><?php the_sub_field('title'); ?></a></li>
<?php endwhile;?>
</ul>
<?php endif; ?>
</nav>
Then in my index.php
file, I have div.content
. In this div, I would like to output a list of the corresponding slide
subfield. How can I do this?
// index.php //
<div class="content"></div>
You could repeat a similar loop in the index.php file –
Or you could grab the entire array of data associated with the repeater using get_field(‘slides’, $frontpage_id); – set that as a global variable and then use a foreach loop in both files. I think the first option is easier.