Skip to content

Instantly share code, notes, and snippets.

@cezarpopa
Created June 6, 2014 12:03
Show Gist options
  • Save cezarpopa/a6a52476e917ee96ecdc to your computer and use it in GitHub Desktop.
Save cezarpopa/a6a52476e917ee96ecdc to your computer and use it in GitHub Desktop.
Wordpress Query posts - custom posts with different background for each post using count++
<?php
$mimo_query = new WP_Query(
array(
'post_type' => 'petreceri',
//'showposts' => 8,
'no_found_rows' => true,
)
);
if( $mimo_query->posts ) { ?>
<div class="col_12">
<?php
// Begin Loop
$mimo_count=0;
foreach( $mimo_query->posts as $post ) : setup_postdata( $post );
$mimo_count++;
?>
<div class="col_4 petreceri-<?php echo $mimo_count; ?>">
<?php the_title(); ?>
</div>
<?php if( $mimo_count==4 ) { $mimo_count=0; } endforeach; ?>
</div><!-- /petreceri -->
<?php } wp_reset_postdata(); $mimo_query = NULL; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment