• 行走
  • typecho获取分类及其数量

public static function getclassifyNum($widget)
    {
        $db = Typecho_Db::get();
        $rows = $db->fetchAll($db->select()
            ->from('table.metas')
            ->where('table.metas.type = ?', 'category'));
        $stat = array();
        foreach ($rows as $row) {
            $row = $widget->filter($row);
            $arr = array(
                'name' => $row['slug'],
                'num' => $row['count']
            );
           array_push($stat,$arr);
        }
        return $stat;
    }
<div class="sidebar-box classListBox">
         <div class="p-3">分类详情</div>
               <ul>
             <?php $classlist = Ctx::getclassifyNum($this);
            foreach ($classlist as $posts) : ?>
            <li><?php print_r($posts['name']) ; ?> <span class="classNum"><?php print_r($posts['num']) ; ?></span></li>
                 <?php endforeach; ?>
        </ul>
     </div>

CSS

.classListBox li{
list-style: none;
    margin-bottom: 15px;
    padding-right: 40px;
}
.classNum{
    float: right;
    background-color: rgba(255,78,106,.1);
    display: inline-block;
    width: 26px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    border-radius: 100%;
    color: #ff4e6a;
}