I am trying to add a div class="row"
after every four posts in my wordpress website. The following code is used to generate the post types on my page:
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=8&post_type=branding'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="col-md-3">
<div class="featured-project-image">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
else { echo'<img src="';
echo get_bloginfo( 'stylesheet_directory' );
echo'/images/placeholder.jpg"/>'; } ?>
</div>
</div>
<?php endwhile;?>
The following should do what you want
Starting the
div
before the while loop ensures the first 4 are also contained in a row.Create variable, iterate it in each loop step and check if
% 4 == 0;
: