要解决此问题,可以创建page template, 在此页面模板上
1.仅获取顶级类别,将父值设置为零
$args = array(
\'orderby\' => \'name\',
\'parent\' => 0
);
$categories = get_categories( $args );
2。获取所有父类别中的帖子
foreach ( $categories as $category ) {
$all_posts=get_post(\'category=\'.$category->term_id);
foreach( $myposts as $post ){
setup_postdata($post)
echo\'<li>\';\'
echo\'<a href="\'.the_permalink().\'">\'.the_title().\'</a>\';\'
echo\'</li>\';\'
}
}
3。如果不想创建页面模板,则
在类别中。php(根据您的设计要求进行修改)
// Get children categories of current cat if they exist
if ( $excludes = get_categories( "child_of=" . $wp_query->get( \'cat\' ) ) ) {
// For each child, add just the ID to an array
foreach ( $excludes as $key => $value ) {
$exs[] = $value->term_taxonomy_id;
}
}
// In Loop
if(have_post()){
while(have_posts()){
the_post();
//get all category of current post
$categories = get_the_category();
foreach($categories as $category) {
//check if any category is child category of current category
if( in_array($category,$exs) )
continue;
}
the_title();
}
}