Home › Forums › Add-ons › Repeater Field › Repeater display Data on (2) Columns of a Table?
Hello…I am using the Repeater to list my items..and everything seems to be working perfectly…However my question is, I created a Table that has 2 rows…but I notice the Repeater stacks the data one after another…How can I set the data to also display within the 2nd row on a Table?
Below is a copy of the code I am using – you will see the TABLE section to get an idea of what i was trying to do…
<?php if(get_field('list_of_games')): ?>
<?php while(has_sub_field('list_of_games')): ?>
<?php $post_object = get_sub_field('game_name');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<TABLE class="tg-table-plain">
<tr>
<td><img src= "<?php $image = get_sub_field('image'); echo $image['sizes']['medium']; ?>" /></td>
<td><img src= "<?php $image = get_sub_field('image'); echo $image['sizes']['medium']; ?>" /></a></td>
</tr>
<tr>
<td class="game-title3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php the_sub_field('game_snippet'); ?></td>
<td class="game-title3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_sub_field('game_snippet'); ?></td>
</tr>
</TABLE>
<span><?php the_sub_field('list_of_games'); ?></span>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
I appreciate your help. Thank you.
Hi @WPDragon
Your code looks to create a new table elements for each row in the repeater field.
In each table element, you have 2 rows (<tr>
) and have duplicated the content for each cell.
I don’t understand what your code is trying to do, so perhaps you can clearly describe what you want the end result to be?
Thanks
E
Ya, thats my issue…I know im not doing it correctly, and its duplicating…but that idea is lets say I want to display 6 items from the repeater…instead of the 6 items being listed straight down 1 row….i want it to also display on the 2nd row…for example, item 1, 2, 3 on left, and then item 4, 5, 6 right.
hmmm, hopefully kindda makes sense what i mean….i know im not setting something up properly.
thanks!
I guess simply, my question is…How can I set the repeater to display in 2 columns without duplicating?
Thanks.
Hi @WPDragon
Can you please clarify what you mean by How can I set the repeater to display in 2 columns
. This can be interpreted in many different ways. Use the example of having 6 rows of data, is this what you want to do:
1 2
3 4
5 6
Hi @elliot – sorry for the confusion & i appreciate your patience.
Yes, that is exactly what I want to do.
Hi @WPDragon
I have whipped up some code which should produce the desired markup. Please take some time to read over and understand it line by line before using it:
<?php
$i = 0;
if( have_rows('list_of_games') ): ?>
<table class="tg-table-plain">
<?php while( have_rows('list_of_games') ): the_row(); $i++;
$post = get_sub_field('game_name');
if( empty($post) )
{
continue;
}
setup_postdata( $post );
?>
<?php if( $i == 1 ): ?>
<tr>
<?php endif; ?>
<td>
<div class="image">
<img src= "<?php $image = get_sub_field('image'); echo $image['sizes']['medium']; ?>" />
</div>
<div class="title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<div class="snippet">
<?php the_sub_field('game_snippet'); ?>
</div>
<div class="list-of-games">
<?php the_sub_field('list_of_games'); ?>
</div>
</td>
<?php if( $i == 2 ): $i = 0; ?>
</tr>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Thanks
E
Hi,
I have a similar problem. I have multiple lists of series. Each series has multiple sessions. So, I tried to build a repeater inside a repeater, like this.
Download Content – Repeater
— Series Title – Text
— Session Title – Repeater
— Title
— Speaker
1 table per series
1 row for each session title
This is what I have so far, and all I can get is the main series title, but it’s not calling any of the sessions: http://4-11.org/download/?page_id=2
<?php
$rows = get_field('download_content');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>' . $row['series_title'] ;
$rows = get_field('session_title') ;
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>' . $row['title']. ','. $row['speaker'] .', etc</li>';
}
echo '</ul></li>';
}
}
echo '</ul>';
}
?>
The topic ‘Repeater display Data on (2) Columns of a Table?’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.