逐一列出类别和帖子

时间:2016-06-03 作者:codieboie

我想在一个页面中显示所有类别及其帖子,用于动态网站。请帮忙

-category a
  -post a1
  -post a2
  -post a3
-category b
  -post b1
  -post b2 
  -post b3

1 个回复
SO网友:Guy Ytzhak
$categories = get_categories( array( \'child_of\' => 10 ); 
    foreach ( $categories as $category ) {
    $args = array(
        \'posts_per_page\'   => 5,
        \'offset\'           => 0,
        \'category\'         => category ,
        \'category_name\'    => \'\',
        \'orderby\'          => \'date\',
        \'order\'            => \'DESC\',
        \'include\'          => \'\',
        \'exclude\'          => \'\',
        \'meta_key\'         => \'\',
        \'meta_value\'       => \'\',
        \'post_type\'        => \'post\',
        \'post_mime_type\'   => \'\',
        \'post_parent\'      => \'\',
        \'author\'       => \'\',
        \'post_status\'      => \'publish\',
        \'suppress_filters\' => true 
    );
    $posts_array = get_posts( $args );

    foreach($posts_array as $post) {
    // do anything you want with $post
    }
}