我试图解决这个问题一段时间,但我无法找到一个令人满意的方式来得到我想要的。也许这很简单,但我太没经验了。
我需要一种方法来显示给定类别的子类别的所有文章标题,如下所示:
Category "x"
Subcategory 1xa
Post 1xa
Post 2xa
Subcategory 2xb
Post 1xb
Post 2xb
Category "y"
Subcategory 1ya
Post 1ya
Post 2ya
Subcategory 2ab
Post 1yb
Post 2yb
etc
我真的不能用我有限的知识来做这件事。我所能得到的只是子类别列表(没有帖子标题)或每个类别、子类别和帖子的列表。我想让每个类别、子类别和帖子都在它们下面(未分类的除外),就像上面的顺序一样。我看到了很多帖子,但没有找到解决方案,因为我不擅长编码。谁能帮我一下吗?提前非常感谢!
<?php
$cat_args = array(
\'show_option_all\' => \'\',
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
$categories = get_categories( $cat_args );
foreach( $categories as $category ) {
$args = array(
\'showposts\' => -1,
\'category__in\' => array( $category->term_id ),
\'caller_get_posts\'=> 1
);
$posts = get_posts( $args );
if( $posts ) {
echo \'<p>Category: <a href="\' . get_category_link( $category->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name.\'</a> </p> \';
foreach($posts as $post) {
setup_postdata( $post ); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>