Hi,
I want to get data from another page but limit the items it returns to 6. Is there a easy way to do this. My code is below and that returns all results.
Any help much appreciated
Ryan
<?php if( get_field('gallery', '2850') ): ?>
<div class="times-content">
<?php while( has_sub_field('gallery', '2850') ): ?>
<div class="image hover">
<a href="<?php the_sub_field('image'); ?>" class="fancybox-img" title="<?php the_sub_field('title'); ?>">
<img src="<?php the_sub_field('image'); ?>" alt="<?php the_sub_field('title'); ?>" width="150" height="150" />
<div class="info">
<p><?php the_sub_field('title'); ?></p>
<p><?php the_sub_field('hashtags'); ?></p>
</div>
</a>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
Hi @strohy85
A simple counter will allow you to limit the results of a loop.
Like so:
<?php $i = 0; ?>
<?php while( has_sub_field('gallery', '2850') ): ?>
<?php $i++; ?>
<?php if($i > 6){ break; } ?>
<!-- HTML here -->
<?php endwhile; ?>
Elliot,
what if there are a total of 12 results and I just wanted to show the last 4?? So results 8-12