0
votes

First time question, long time reader. I couldn't find any answers to this, or maybe i'm not quite searching correctly. Hopefully you can help me.

I have three categories. Each category has an unlimited amount of posts. I only need to display the title and the date.

The problem is that I want to loop one post at a time from each category. The posts must be ordered by date.

A very basic example of the output i'm trying to achieve:

  • Category 1: Post one title and date
  • Category 2: Post one title and date
  • Category 3: Post one title and date
  • Category 1: Post two title and date
  • Category 2: Post two title and date
  • Category 3: Post two title and date
  • Category 1: Post three title and date
  • Category 2: Post three title and date
  • Category 3: Post three title and date

and so on...

I hope this doesn't sound to confusing. Thanks for your time.

1

1 Answers

0
votes

One possibility is to simply create three sets of get_posts(). One of them is set to category 1, the others are 2 and 3 respectively. From there you can set up a loop using a few foreach statements that store the title and date into a multidimensional array that you iterate through and echo a moment later.

If that was a bit hard to follow:

Lets assume that we have already selected the three get_post( $args ) where $cat1, $cat2 and $cat3 are the resulting posts. $c starts as 0 for this.

foreach ($cat1 as $post) : setup_postdata($post);
  $cat1Array[$c] = the_title( false, false, false ) . the_date( false, false, false, false );
  $c++;
endforeach

Which is repeated twice to give $cat2Array and $cat3Array:

for ($c=0; $c<=<iterations>; $c++) {
  echo $cat1Array[$c];
  echo $cat2Array[$c];
  echo $cat3Array[$c];
}