Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress:如何列出所有子类别';一页中的第一篇文章?_Wordpress_Categories_Posts - Fatal编程技术网

WordPress:如何列出所有子类别';一页中的第一篇文章?

WordPress:如何列出所有子类别';一页中的第一篇文章?,wordpress,categories,posts,Wordpress,Categories,Posts,我有一个类别有600个子类别, 有没有办法列出所有子类别,每个子类别中有一篇文章 sub-1最新职位名称 sub-2最新职位名称 sub-3最新职位名称 sub-4最新职位名称 sub-5最新职位名称 sub-6最新职位名称 sub-7最新职位名称 sub-8最新职位名称 为了检索所有子类别,请使用 例如: $args = array( 'type' => 'post', 'parent' => 'your

我有一个类别有600个子类别, 有没有办法列出所有子类别,每个子类别中有一篇文章

  • sub-1最新职位名称
  • sub-2最新职位名称
  • sub-3最新职位名称
  • sub-4最新职位名称
  • sub-5最新职位名称
  • sub-6最新职位名称
  • sub-7最新职位名称
  • sub-8最新职位名称

为了检索所有子类别,请使用

例如:

$args = array(
'type'                     => 'post',
'parent'                   => 'your_parent_category_id',
'orderby'                  => 'name',
'order'                    => 'ASC' );

$your_categories = get_categories( $args );
要获取帖子,请循环浏览结果并使用:

$args = array(
    'numberposts'     => 1,
    'offset'          => 0,
    'category'        => your_subcategories,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'post_type'       => 'post',
    'post_status'     => 'publish' );

$your_posts = get_posts( $args );