Typecho自定义二级菜单样式

$this->widget('Widget_Metas_Category_List')

       ->parse('<li class="menu-item"><a href="{permalink}">{name}</a></li>');

或者

$this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list');
他们都是用了Widget_Metas_Category_List组件。我们只需要把这个组件里的分类数据读取出来自己输出就好了,还是模板和数据分类的问题。

首先我们在模板里读取分类数据存储到$categories,然后对他进行循环输出即可。通过阅读Widget_Metas_Category_list的源代码,写出了下面这段代码来输出categories,只要用它替换上面哪行listCategories或者parse调用即可

<?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
<?php if ($category->have()): ?>
<?php while ($category->next()): ?>

<?php if ($category->levels == 0): ?>
    <?php $children = $category->getAllChildren($category->mid); ?>
    <?php if (empty($children)) :?>
        <li><a href="<?php $category->permalink() ?>"> <?php $category->name() ?></a></li>
    <?php else : ?>
        <li class="dropdown">
            <a href="<?php $category->permalink() ?>" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php $category->name() ?><span class="caret"></span></a>
            <ul class="dropdown-menu">
                <?php foreach ($children as $child ): ?>
                    <?php $child = $category->getCategory($child) ?>
                    <li class=""><a href="<?php echo $child['permalink']; ?>"> <?php echo $child['name']; ?></a></li>
                <?php endforeach ?>
            </ul>
        </li>
    <?php endif ?>
<?php endif ?>

<?php endwhile; ?>
<?php endif ?>

发表新评论