Skip to content

Instantly share code, notes, and snippets.

@neverything
Created February 7, 2013 13:37
Show Gist options
  • Save neverything/4730968 to your computer and use it in GitHub Desktop.
Save neverything/4730968 to your computer and use it in GitHub Desktop.
Sample index.php file to show how you could create a new row after two posts.
<?php
/**
* Sample index.php file for displaying two posts per row
*/
get_header(); ?>
<!-- Row for main content area -->
<div id="content" class="row">
<div id="main" class="twelve columns" role="main">
<div class="post-box">
<?php if ( have_posts() ) : ?>
<?php
(int) $posts_counter = 1; // Initiate custom counter
while ( have_posts() ) : the_post();
if ( $posts_counter % 2 == 1 ) {
echo '<div class="row">'; // draw the opening div.row
}
?>
<div class="six columns">
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php
// Make sure we close the row after the last post anyways.
if ( $posts_counter % 2 == 0 || $posts_counter == $wp_query->post_count ) {
echo '</div>'; // draw the closing div.row
}
$posts_counter++; // +1 for the counter
endwhile;
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
<?php if ( function_exists( 'required_pagination' ) ) {
required_pagination();
} ?>
</div>
</div><!-- /#main -->
</div><!-- End Content row -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment