Home › Forums › Add-ons › Repeater Field › Repeater in Two Columns (again) › Reply To: Repeater in Two Columns (again)
For 1) and 2)
Are you restricted on old browser supports? cause i’d 100% suggest you just use the css columns to do that layout. it’s supported on all browser last 2 latest version now.
http://caniuse.com/#search=column
Example:
<ul class="items">
<?php while (have_rows('appetizers')): the_row(); ?>
<li>
<h4><?php the_sub_field('item'); ?></h4>
<p><?php the_sub_field('desc'); ?>$<?php the_sub_field('price'); ?></p>
</li>
<?php endwhile; ?>
</ul>
<style>
.items {
column-count: 2;
column-gap: 20px;
}
</style>
If you can’t or don’t wanna use the css way, this is a cleaner way to split them:
<?php
// get repeater values as array
$appetizers = get_field('appetizers');
// calculate how many items first
$items_count = count($appetizers);
// calculate how much half is, round up
$items_half = ceil($items_count / 2);
// split the repeater
$appetizers_chunks = array_chunk($appetizers, $items_half);
?>
<div class="section">
<div class="secthead"><?php the_title( '<h2>', '</h2>' ); ?></div>
<?php foreach ($appetizers_chunks as $chunk): ?>
<div class="items">
<ul>
<?php foreach ($chunk as $value): ?>
<li>
<h4><?php echo $value['item']; ?></h4>
<p><?php echo $value['desc']; ?> $<?php echo $value['price']; ?></p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
3) i’m not sure if i understand the question. Is your repeater field not already set on the category edit? where’s the repeater field at?
Cheers
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.