I'm creating a 4 column archive page template for a custom post type I created in Wordpress and I can't seem to get the posts to display properly. I'm mirroring Visual Composer's layout to match the rest of my site. After looking at Wordpress Loop posts in Bootstrap 3 grid layout I've been able to get close with the following code:
<div class="wpb_row">
<div class="col span_12">
<?php
$args=array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '';
$i = 0;
while ($my_query->have_posts()) : $my_query->the_post();
if($i % 4 == 0) { ?>
<?php
}
?>
<div class="vc_span3 wpb_column column_container">
<div class="wpb_wrapper">
<a href="<?php the_permalink() ?>"><img src="<?php the_field('catalog_image'); ?>" alt="<?php the_field('product_description'); ?>" /></a>
<div class="wpb_text_column wpb_content_element ">
<div class="wpb_wrapper">
<h3><?php the_title(); ?></h3>
<h3>$<?php the_field('product_price'); ?></h3>
</div>
</div>
</div>
</div>
<?php
if($i % 4 == 0) { ?>
<?php
}
$i++;
endwhile;
}
wp_reset_query();
?>
</div>
</div>
Both the outer divs wpb_row
and col span_12
repeat every 4 columns. Currently it displays the posts in 4 columns but they return more than 4 posts within the row(they overflow to the next row). Ideally the layout would be like this:
<div class="wpb_row">
<div class="col span_12">
<div class="vc_span3 wpb_column column_container">
<!--Post #1 Content-->
</div>
<div class="vc_span3 wpb_column column_container">
<!--Post #2 Content-->
</div>
<div class="vc_span3 wpb_column column_container">
<!--Post #3 Content-->
</div>
<div class="vc_span3 wpb_column column_container">
<!--Post #4 Content-->
</div>
</div>
</div>
<!--Repeat everything in wpd_row on next row starting at Post #5 and so on -->
Could anyone offer advice on how to correct this? Thanks in advance.