typecho导航调用分类,并实现折叠效果

2018-12-16T15:26:00

最近开始尝试开发typecho模板,说实话是相当容易了,大多数的功能百度一下都有解决方案的教程,所以制作起来也算容易,只不过没有模板引擎的缘故,各种标签其实就是php的代码。然后对于博客新的页面,希望以更加直观的方式呈现分类,所以要实现折叠显示的效果,其实效果这些css就可以解决,主要还是数据的循环调用问题,查阅了很多的资料,进行多次调试之后,才完善起来,所以决定记录下来。

代码如下:

<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?>
<?php while($categorys->next()): ?>
<?php if ($categorys->levels === 0): ?>
<?php $children = $categorys->getAllChildren($categorys->mid); ?>
<?php if (empty($children)) { ?>
<li id="menu-item-<?php $categorys->mid(); ?>" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-<?php $categorys->mid(); ?>"><a href="<?php $categorys->permalink(); ?>"><?php $categorys->name(); ?></a></li>
<?php } else { ?>
<li id="menu-item-<?php $categorys->mid(); ?>" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-<?php $categorys->mid(); ?>"><a href="<?php $categorys->permalink(); ?>"><?php $categorys->name(); ?><span class="caret"></span></a>
<ul class="sub-menu">
<?php foreach ($children as $mid) { ?>
<?php $child = $categorys->getCategory($mid); ?>
<li id="menu-item-<?php echo $child['mid'] ?>" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-<?php echo $child['mid'] ?>"><a href="<?php echo $child['permalink'] ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php endif; ?>
<?php endwhile; ?>

循环出的html代码截图,可以看到子类在父类标签内部被循环调出:

最终效果如下:

【最后,请期待一下博客的新界面吧】

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »