【发布时间】:2012-10-20 16:49:57
【问题描述】:
我有一个类别有 600 个子类别, 有没有办法用每个子类别的一篇文章列出所有子类别?
- sub-1 最新帖子标题
- sub-2 最新帖子标题
- sub-3 最新帖子标题
- sub-4 最新帖子标题
- sub-5 最新帖子标题
- sub-6 最新帖子标题
- sub-7 最新帖子标题
- 分8个最新帖子标题
【问题讨论】:
标签: wordpress categories posts
我有一个类别有 600 个子类别, 有没有办法用每个子类别的一篇文章列出所有子类别?
【问题讨论】:
标签: wordpress categories posts
为了检索所有子类别,请使用get_categories()。
例子:
$args = array(
'type' => 'post',
'parent' => 'your_parent_category_id',
'orderby' => 'name',
'order' => 'ASC' );
$your_categories = get_categories( $args );
要获取帖子,请遍历结果并使用get_posts():
$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 );
【讨论】: