If you're looking for a simple JavaScript function that utilizes jQuery, this might be helpful:
function arrangePosts(container){
$(container).find('.post-item').each(function(){
$(this).appendTo('.col-append');
var nextColumn = $('.col-append').next('div');
$('.col-append').removeClass('col-append');
if(nextColumn.size()){
nextColumn.addClass('col-append');
} else {
$('.post-col').first().addClass('col-append');
}
});
}
To use it, simply call:
arrangePosts('#container-with-posts');
This function essentially goes through each element with the class post-item
and organizes them into columns designated by the class post-column
Your HTML structure should resemble the following:
<div class="posts-columns">
<div class="post-col col-append"></div>
<div class="post-col"></div>
<div class="post-col"></div>
</div>
<div id="container-with-posts">
<div class="post-item> <!-- Post content here --> </div>
<div class="post-item> <!-- Post content here --> </div>
</div>
Remember to adjust the styling or modify the code to align with your CSS preferences.