0

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.

4

1 回答 1

0

一种可能性是简单地创建三组 get_posts()。其中一个设置为类别 1,其他分别为 2 和 3。从那里,您可以使用一些 foreach 语句设置一个循环,这些语句将标题和日期存储到一个多维数组中,您可以迭代并稍后回显。

如果这有点难以理解:

假设我们已经选择了三个 get_post( $args ),其中 $cat1、$cat2 和 $cat3 是生成的帖子。$c 为此从 0 开始。

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

重复两次以给出 $cat2Array 和 $cat3Array:

for ($c=0; $c<=<iterations>; $c++) {
  echo $cat1Array[$c];
  echo $cat2Array[$c];
  echo $cat3Array[$c];
}
于 2013-05-05T14:53:29.990 回答