Tyepcho像CMS一样,输出所有分类+文章 - 夏目友人帐

Tyepcho像CMS一样,输出所有分类+文章

"夏目贵志" 发表于: 2018年04月02日

像CMS那样,输出全部分类,并按分类输出文章

/* 循环所有的分类 */
<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while ($categories->next()): ?>
 
/* 循环当前分类下的文章 */
<?php $this->widget('Widget_Archive@category-' . $categories->mid, 'pageSize=7&type=category', 'mid=' . $categories->mid)->to($posts); ?>
<div class="posts">
<?php while ($posts->next()): ?>
<?php if (1 == $posts->sequence): ?>  //判断第一篇文章
<h3>[<?php $categories->name(); ?>]:<a href="<?php $posts->permalink(); ?>"><?php $posts->title(43); ?></a></h3>
<?php $posts->excerpt(120, '...'); ?>
<ul class="post-list">  //文章列表
<?php else: ?>
<li>
<a href="<?php $posts->permalink(); ?>"><?php $posts->title(40); ?></a>
<span class="comment-num">(<?php $posts->commentsNum(); ?>)</span>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
</div>
<?php endwhile; ?>

转载自:https://app.typecho.me/coder/21.html

像CMS那样,输出全部分类,并按分类输出文章

/* 循环所有的分类 */
<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while ($categories->next()): ?>
 
/* 循环当前分类下的文章 */
<?php $this->widget('Widget_Archive@category-' . $categories->mid, 'pageSize=7&type=category', 'mid=' . $categories->mid)->to($posts); ?>
<div class="posts">
<?php while ($posts->next()): ?>
<?php if (1 == $posts->sequence): ?>  //判断第一篇文章
<h3>[<?php $categories->name(); ?>]:<a href="<?php $posts->permalink(); ?>"><?php $posts->title(43); ?></a></h3>
<?php $posts->excerpt(120, '...'); ?>
<ul class="post-list">  //文章列表
<?php else: ?>
<li>
<a href="<?php $posts->permalink(); ?>"><?php $posts->title(40); ?></a>
<span class="comment-num">(<?php $posts->commentsNum(); ?>)</span>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
</div>
<?php endwhile; ?>

转载自:https://app.typecho.me/coder/21.html

添加新评论