处理好了header与面包屑,接下来就按照自己的需求自由发挥了,先放一个分类列表,再挑出一个喜欢的标签,自定义一个该标签下内容展示模块。Typecho 提供了多种文章循环方式,以下是常用的几种方法:
标准文章循环
<?php while($this->next()): ?>
<article>
<h2><a href="<?php $this->permalink() ?>"><?php $this->title() ?></a></h2>
<div class="post-meta">
发布于 <?php $this->date(); ?> | 分类:<?php $this->category(','); ?>
</div>
<div class="post-content">
<?php $this->content('阅读更多...'); ?>
</div>
</article>
<?php endwhile; ?>
分页控制
<?php $this->pageNav('«', '»', 3, '...', array(
'wrapTag' => 'div',
'wrapClass' => 'pagination',
'itemTag' => 'span',
'textTag' => 'span',
'currentClass' => 'current',
'prevClass' => 'prev',
'nextClass' => 'next'
));
自定义查询循环
<?php
$posts = Typecho_Widget::widget('Widget_Archive@custom',
'type' => 'post',
'pageSize' => 5,
'orderBy' => 'created',
'order' => 'DESC'
);
while($posts->next()): ?>
<h3><a href="<?php $posts->permalink(); ?>"><?php $posts->title(); ?></a></h3>
<?php endwhile; ?>
按分类循环
<?php
$this->widget('Widget_Archive@categoryPosts', 'type=category', 'mid=3')
->parse('<h3><a href="{permalink}">{title}</a></h3>');
?>
按标签循环
<?php
$this->widget('Widget_Archive@tagPosts', 'type=tag', 'mid=5')
->parse('<h3><a href="{permalink}">{title}</a></h3>');
?>
最新文章列表
<?php
$this->widget('Widget_Contents_Post_Recent', 'pageSize=5')
->to($recentPosts);
while($recentPosts->next()): ?>
<li><a href="<?php $recentPosts->permalink(); ?>"><?php $recentPosts->title(); ?></a></li>
<?php endwhile; ?>
随机文章列表
<?php
$this->widget('Widget_Contents_Post_Random', 'pageSize=5')
->to($randomPosts);
while($randomPosts->next()): ?>
<li><a href="<?php $randomPosts->permalink(); ?>"><?php $randomPosts->title(); ?></a></li>
<?php endwhile; ?>
热门文章(按评论数)
<?php
$this->widget('Widget_Contents_Post_Hot', 'pageSize=5')
->to($hotPosts);
while($hotPosts->next()): ?>
<li><a href="<?php $hotPosts->permalink(); ?>"><?php $hotPosts->title(); ?></a></li>
<?php endwhile; ?>
自定义字段筛选
<?php
$this->widget('Widget_Archive', array(
'type' => 'post',
'pageSize' => 5,
'fields' => array('featured' => '1')
))->to($featuredPosts);
while($featuredPosts->next()): ?>
<li><a href="<?php $featuredPosts->permalink(); ?>"><?php $featuredPosts->title(); ?></a></li>
<?php endwhile; ?>
多循环共存
<?php
// 第一个循环
$this->widget('Widget_Archive@loop1', 'type=post', 'pageSize=3')
->to($loop1);
while($loop1->next()): ?>
<div class="loop1"><?php $loop1->title(); ?></div>
<?php endwhile; ?>
// 第二个循环
$this->widget('Widget_Archive@loop2', 'type=post', 'pageSize=5', 'orderBy=commentsNum')
->to($loop2);
while($loop2->next()): ?>
<div class="loop2"><?php $loop2->title(); ?></div>
<?php endwhile; ?>
以上是Typecho中常用的文章循环方式,可以根据实际需求选择合适的方法或进行组合使用。