How to show posts of an columnized different categories on the same line or row?

One way to output the same query yet style it differently is to use current_post or in combination with rewind_posts, or using rewind_posts alone.

So for example:

Your initial query

 if ($my_query->have_posts()) :while ($my_query->have_posts()) : $my_query->the_post();

  $counter_id = $my_query->current_post + 1;   //this is the counter

// then use a conditional to style each on based on `# or %

 if ($wp_query->current_post % 2 == 0)

// add custom styles

endwhile; else:

// 
// Or rewind the post with a count and conditional

rewind_posts();  //rewind the post back to the start

if $counter_id == 1  //do some style
if $counter_id > 3   // do some style
//etc

Another more simple option is to just use multiple separate loops (and DB query’s)

I hope this logic makes sense and helps , I don’t have the time to actually write your query and test it.

Leave a Comment