详情页

typecho index.php首页模板制作常用代码

时间:2023年10月05日

编辑:佚名

模板的制作并非难事,只要你写好了HTML和CSS,嵌套模板就非常简单了,你无需了解标签的内部结构,你只要会使用,模板就能迅速完成。这篇文章只简单的介绍了常用标签的使用方法,希望能带你进入模板的世界。
模板信息
我们先从主文件说起,打开这个文件,首先看到的是注释:
/**
 * 这是typecho系统的一套默认皮肤。你可以在<a href="http://typecho.org">typecho的官方网站</a>获得更多关于此皮肤的信息
 * 
 * @package Typecho Default Theme 
 * @author typecho
 * @version 1.0.0
 * @link http://typecho.org
 */
这是模板信息存放的地方,它将在后台都模板选择页显示。
前两行是简短的介绍,每个“*”表示一个段落。
@package 表示模板名,
@author 表示作者名,
@version 是模板的版本号,
@link 是作者的网站连接。
紧挨着注释下方的 include(‘header.php’),在结尾处也会看到 include(‘sidebar.php’) 和 include(‘footer.php’)。这些语句用来调用模板的其它模块。header故名思议是页首,sidebar是侧栏,footer是页脚。
显示文章
<?php while($this->next()): ?>
    <div class="post">
    <h2 class="entry_title"><a href="<?php $this->permalink() ?>"><?php $this->title() ?></a></h2>
    <div class="entry_data">
        Published by <a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a> on <?php $this->date('F j, Y'); ?> in <?php $this->category(','); ?>.
        <?php $this->commentsNum('%d Comments'); ?>.
    </div>
    <div class="entry_text">
        <?php $this->content('Continue Reading...'); ?>
    </div>
    </div>
<?php endwhile; ?>
进入文章循环,输出文章,剥开html代码,一句一句介绍
<?php $this->permalink() ?>     文章所在的连接
<?php $this->title() ?>     文章标题
<?php $this->author(); ?>     文章作者
<?php $this->author->permalink(); ?>     文章作者地址
<?php $this->date('F j, Y'); ?>     文章的发布日期,格式可参考PHP日期格式
<?php $this->category(','); ?>     文章所在分类
<?php $this->commentsNum('%d Comments'); ?>     文章评论数及连接
<?php $this->content('Continue Reading...'); ?>     文章内容,其中的“Continue Reading…”是显示摘要时隐藏部分的邀请连接
好了,文章显示结束,别忘了结束循环。
文章分页
<?php $this->pageNav(); ?>
文章输出结束后别忘了增加分页,至此,index.php的常见内容结束,应该不糊涂吧。
相关文章
猜你需要