I’m creating a custom wordpress theme using the Bootstrap Framework.
I need the loop through the blog posts in rows of 2.
The HTML output I need as follows:
<div class="row">
<div class="col-md-6 blog-item text-center">
<div class="blog-padding blog-indx-panel">
<div><a href="link to post here"><img class="img-responsive" alt="" src="/wp-content/uploads/2015/05/featured-image1.jpg"></a></div>
<h3>POST TITLE #1</h3>
<p class="blog-date">10 FEBRUARY 2015</p>
<p>Blog Excerpt Shown Here</p>
<div><a class="btn btn-default btn-text" href="linktoposthere" role="button">Read Full Post</a></div>
</div>
</div>
<div class="col-md-6 blog-item text-center">
<div class="blog-padding blog-indx-panel">
<div><a href="link to post here"><img class="img-responsive" alt="" src="/wp-content/uploads/2015/05/featured-image1.jpg"></a></div>
<h3>POST TITLE #1</h3>
<p class="blog-date">16 FEBRUARY 2015</p>
<p>Blog Excerpt Shown Here</p>
<div><a class="btn btn-default btn-text" href="#linktoposthere" role="button">Read Full Post</a></div>
</div>
</div>
</div>
But I’m unsure on how to create a php loop in wordpress to get the desired output.
Any ideas?
You should read up on the modulo operator. It’s really helpful for these situations. Below I have two versions, the top is documented and uses braces (makes it easier to read) and the bottom does the same thing in the least code.
Way One
Way Two
Try this: