wordpress在一级分类的页面里显示二级分类

首页 > 科技 > 自然 > 正文 2018-05-01

由于本博基本上都存在二级分类,所以有必要在wordpress在一级分类的页面里显示该分类下的二级分类,比如以下几个分类:

世界之最》生物界之最

世界之最》人类之最

世界之最》自然界之最

必须在博友们点开世界之最分类的时候,页面右侧的导航变成生物界之最,人类之最,自然界之最

在网上找了很多代码,终于找到如下一段比较合适使用。

    global $cat;
    $cats = get_categories(array(
        "child_of" => $cat,
        "parent" => $cat,
        "hide_empty" => 0
    ));
    $c = get_category($cat);
    if(empty($cats)){
?>

   
   
       

" href="">


       


       

">全文阅读>>


        | 标签:
   
   
   
       

文章稍后更新


   


   
   

}else{
    foreach($cats as $the_cat){
        $posts = get_posts(array(
            "category" => $the_cat->cat_ID,
            "numberposts" => 10,
        ));
        if(!empty($posts)){
            echo "
           
               

name."" href="".get_category_link($the_cat)."">".$the_cat->name."

 
               

自然推荐文章

自然热门文章

推荐内容