Last active
February 13, 2016 19:47
-
-
Save twentyfortysix/ee20de5cb11e89508588 to your computer and use it in GitHub Desktop.
WP - loop column braker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Query | |
$the_query = new WP_Query( $args_e ); | |
if ($the_query->have_posts()) : | |
$out .= '<h4 class="subtitle">'.__('Výhry', 'xyz').'</h4>'; | |
// The Loop | |
$actual_post_count = ($the_query->post_count); | |
$divide_by = 2; | |
$i = 0; | |
while ( $the_query->have_posts() ) : | |
$the_query->the_post(); | |
$postClass = get_post_class(array('col-md-6')); | |
$postClassString = ''; | |
foreach($postClass as $class){ | |
$postClassString .= $class . ' '; | |
} | |
if($i == 0 || $i%$divide_by == 0){ | |
$out .= '<div class="row">'; | |
} | |
$out .= '<div class="'.$postClassString.'">'; | |
// the content | |
$out .= '</div>'; | |
// close the row | |
if($i != 0 && ($i+1)%$divide_by == 0 || $actual_post_count == $i+1){ | |
$out .= '</div>'; | |
} | |
$i++; | |
endwhile; | |
endif; | |
// Restore original Query & Post Data | |
wp_reset_postdata(); | |
return $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment