typecho 分类显示层次

Posted on Posted in typecho
Tips: 本文创建于2015年7月10日,已超过 2 年,内容或图片可能已经失效!

后台有个程序也是显示层次的

houtaicengci.png

代码是这样的

houtaicengcidaima.png

我用的自己写的

<?php  
$db = Typecho_Db::get();  
$res = $db->fetchAll($db->select()->from('table.metas')->where('type = ?', 'category'));  
  
function tree(&$res, $p_id = 0, $deep = ''){  
    static $result = array ();  
    foreach($res as $row){  
        if($row['parent'] == $p_id){  
            echo "<li style='margin-top:7px;'>".$deep."<a href=https://liuhonghe.me/category/".$row['slug'].">".$row['name']."</a>(".$row['count'].")</li>";  
            $row['deep'] = $deep;  
            $result[] = $row;  
            tree($res,$row['mid'],$deep.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');  
        }  
    }  
    return $result;  
}  
$new = tree($res,0);  
?>  

效果在ALLCategory

» 转载请注明来源:呢喃 » typecho 分类显示层次

Leave a Reply

Your email address will not be published. Required fields are marked *

thirteen + three =