I'm currently working on displaying recent posts in 'masonry grid'. Because of multiple issues I came out with the idea of displaying pre-defined rows of that grid (due to designed layout).
First I did all that without dynamic content (posts). Then I tried to get WP_Query to work. But instead of displaying multiple posts in one row, I'm displaying one multiplied post per each row.
I already did "more posts" button - and it reveals content as described above too.
I suppose that prev_post()
method may be wrong for that case, but I didn't found in Codex anything that might be better.
Below I attach part of code & screens to better show both problem and desired effect.
$wpb_all_query = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '4',
]);
if ($wpb_all_query->have_posts()) {
while ($wpb_all_query->have_posts()) {
ob_start();
?>
<div class="list_row three_col">
<div class="column column_1_3">
<?php
$wpb_all_query->the_post(); //1 - the newest post
get_template_part('partials/list-single-post-masonry');
?>
</div>
<div class="column column_1_3">
<?php
$wpb_all_query->prev_post(); //2 - older older than 1
get_template_part('partials/list-single-post-masonry');
$wpb_all_query->prev_post(); //3 - older than 2
get_template_part('partials/list-single-post-masonry');
?>
</div>
<div class="column column_1_3">
<?php
$wpb_all_query->prev_post(); //4 - older than 3
get_template_part('partials/list-single-post-masonry');
?>
</div>
</div>
<?php
$generated_content = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
}
}
return $generated_content;