‘category_name’ => ‘gallery’, // category slug
‘posts_per_page’ => -1 // show all posts
);// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {

$c = 1; // counter
$bpr = 4; // number of column in each row

while ( $the_query->have_posts() ) : $the_query->the_post();
?>

if( $c == $bpr ) {
echo ‘

‘;
$c = 0; // back the counter to 0 if the condition above is true.
}
$c++; // increment counter of 1 until it hits the limit of column of every row.

endwhile;
} else {

// no posts found
_e( ‘

Oops!

‘, ‘rys’ );
_e( ‘

Sorry, seems there are no post at the moment.

‘, ‘rys’ );

}

/* Restore original Post Data */
wp_reset_postdata();
?>

http://www.sutanaryan.com/2011/11/how-to-create-or-display-wordpress-post-in-thumbnail-grid-view-design/

Advertisements