waynedunkley
3/4/2015 - 12:43 AM

PHP Loop Wrap every 3 in .row

PHP Loop Wrap every 3 in .row

<?php
	// loop through the rows of data
	$posts_per_row = 3;
	$count = 0;
	while ( have_rows('repeater') ) : the_row();
		$count++;
		if( ( $count - 1 ) % $posts_per_row === 0 && $count !== 0 || $count === 1 ){
			echo '<div class="row">';
		}
		?>

		<div class="col-md-4 col-sm-4">
			<div class="single">
				<?php get_template_part( 'article-list' ); ?>
			</div>
		</div>

		<?php
		if( $count % $posts_per_row === 0 && $count !== 0 ){
			echo '</div>';
		}
	endwhile;
	if( $count % $posts_per_row !== 0 ){
		echo '</div>';
	}
?>