Group Array Data into Sections

Great for repeating content columns, where additional information appears inbetween rows on click.

Wrap the array with array_chunk() in order to initiate a sequence.

<?php $keynote = get_posts($posts);

$split = array_chunk($keynote,3);  // define number of repeating sections from array ?>

<?php foreach($split as $posts) : ?>
	<div class="column-group">
		<?php foreach($posts as $post) : setup_postdata($post); ?>
			<div class="tab-trigger">
				<a href="#" data-toggle="#<?php echo $post->post_name; ?>"></a>
				<!-- content -->
			</div>
		<?php endforeach; ?>
	</div>
	<div class="row-group">
		<?php foreach($posts as $post) : setup_postdata($post);  ?>
			<div class="tab-content" style="display: none;" id="<?php echo $post->post_name; ?>">
				<!-- content appears when item in column-group is clicked -->
			</div>
		<?php endforeach; ?>
	</div>
<?php endforeach; ?>

Use data sort to display the related content.

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.