typecho模板制作代码收集

typecho模板制作代码收集

本文长期收集整理TYPECHO主题制作代码。我为人人,人人为我。

typecho简介

Typecho 是一款博客程序,它在 GPL version 2 许可证下发行,基于 PHP (需要 PHP5 以上版本)构建,可以运行在各种平台上,支持多种数据库(Mysql, PostgreSQL, SQLite)。
网站链接http://typecho.org/

主题结构

header.php

1.编码

打开这个文件,见到如下代码:

<meta http-equiv="content-type" content="text/html; charset=<?php $this->options->charset(); ?>" />

调用默认的编码,现在最经常用的大都是utf-8吧。所以我通常是直接写成utf-8,省去php处理时间。

2.页面标题

<title><?php $this->options->title(); ?><?php $this->archiveTitle(); ?></title>

通常情况下直接复制使用,如果你没有时间的话。

3.导入样式

其中style.css是样式文件相对模板目录的路径和文件名。

4.其它HTML头部信息

<?php $this->header(); ?>

别忘了这句,它关系到RSS信息、客户端程序以及插件的正常使用。

页面导航

本处使用了无序列的页面列表,其中{permalink}是页面的地址,{title}是页面的标题

5.网站名称

<h1><a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title() ?></a></h1>
<span><?php $this->options->description() ?></span>
options->siteUrl(); ?> 网站的首页地址 options->title() ?> 网站名称 options->description() ?> 网站的一些简短描述、介绍

6.站内搜索

 <form method="post" action="">
        <div><input type="text" name="s" class="text" size="32" /> <input type="submit" class="submit" value="Search" /></div>
    </form>

当你的文章很多很多,这个搜索就必不可少。

sidebar.php

最新文章列表

    widget('Widget_Contents_Post_Recent') ->parse('
  • {title}
  • '); ?>
获取最新的10篇文章标题,得到的html是 最新回复列表 获取最新的10个回复,得到的html是 其中excerpt(10, '[...]'); ?>,“10”代表要回复内容截取的字的个数,“[…]”代表省略的意思,你可以自行修改。

文章分类列表

    widget('Widget_Metas_Category_List') ->parse('
  • {name} ({count})
  • '); ?>
输出: 其中{count}是获取该分类下的文章数目。

按月归档

    widget('Widget_Contents_Post_Date', 'type=month&format=F Y') ->parse('
  • {date}
  • '); ?>
输出: 其它连接 这些是可有可无的,只是为了方便登录登出。

footer.php

RSS地址

页脚文件,推荐大家把一些较大的js放在这个文件中最后载入,不会影响阅读。看看我们的footer要讲解些什么?

Entries (RSS)
Comments (RSS).
另外别忘了添加

Typecho
以示对Typecho的支持,简单吧。

现在,你已完成了75%的嵌套,休息一下,后面的会轻松许多 😄

post.php

post页和index是差不多的,但是我们还是要说一下不同之处。

获取Tag 标签

Tags: tags(',', true, 'none'); ?>
这是获取当前单篇文章的标签,用“,”符号隔开。

调用评论页

comments.php

评论列表

commentsNum('No Response', 'One Response to"' . $this->title . '"', '%d Responses to "' . $this->title . '"'); ?>

    comments()->to($comments); ?> next()): ?>
  1. sequence(); ?>. author(); ?> on date('F jS, Y'); ?> at date('h:i a'); ?>
    content(); ?>
还是循环输出评论: theId(); ?> 每个评论的唯一ID sequence(); ?> 评论所在楼层 responseUrl(); ?> 回复地址 responseId(); ?> 回复框ID trackbackUrl(); ?> trackback地址 author(); ?> 评论者的名字 date('F jS, Y'); ?> 评论日期 date('h:i a'); ?> 评论时间 content(); ?> 评论内容

结束循环。我们用有序列表

,因为评论的发表是有先后顺序的。
评论输入表单

allow('comment')): ?>
<h4 id="response">Leave a Reply</h4>

<!-- 输入表单开始 -->
<form method="post" action="<?php $this->commentUrl() ?>" id="comment_form">

    <!-- 如果当前用户已经登录 -->
    <?php if($this->user->hasLogin()): ?>
        <!-- 显示当前登录用户的用户名以及登出连接 -->
        <p>Logged in as <a href="<?php $this->options->adminUrl(); ?>"><?php $this->user->screenName(); ?></a>.
        <a href="<?php $this->options->index('Logout.do'); ?>" title="Logout">Logout &raquo;</a></p>

    <!-- 若当前用户未登录 -->
    <?php else: ?>
        <!-- 要求输入名字、邮箱、网址 -->
    <p><input type="text" name="author" class="text" size="35" value="<?php $this->remember('author'); ?>" /><label>Name (Required)</label></p>
    <p><input type="text" name="mail" class="text" size="35" value="<?php $this->remember('mail'); ?>" /><label>E-mail (Required *will not be published)</label></p>
    <p><input type="text" name="url" class="text" size="35" value="<?php $this->remember('url'); ?>" /><label>Website</label></p>
    <?php endif; ?>

    <!-- 输入要回复的内容 -->
 <p><textarea rows="10" cols="50" name="text"><?php $this->remember('text'); ?></textarea></p>
 <p><input type="submit" value="Submit Comment" class="submit" /></p>
</form>

很多情况下并不对评论文件进行修改,可以直接拿来使用写入相应的css。

其它文件

page.php 页面的显示方式,通常情况下和 single.php 无差别
archive.php 显示某分类下的文章列表、搜索结果列表显示时调用的文件
结语

这篇简短的入门讲解结束了,希望你看着不累,同时能对Typecho的模板系统了解一二,这样文章的目的也就达到了,针对当前文章的不明白的地方,欢迎到互动社区提出问题。

主题所需文件一览表

文件名 作用 必须
style.css 主题样式文件 否
screenshot.png 主题缩略图 否
index.php 首页以及说明文件 是
404.php 404页面文件 否
archive.php 通用(分类、搜索、标签、作者)页面文件 否
category.php 分类页面文件 否
search.php 搜索页面文件 否
tag.php 标签页面文件 否
author.php 作者页面文件 否
comments.php 评论页面文件 否
footer.php 底部页面文件 否
functions.php 主题函数文件 否
header.php 头部页面文件 否
page.php 独立页面文件 否
post.php 日志页面文件 否
sidebar.php 侧边栏页面文件 否
注意:如果archive.php不存在,index.php也会作为通用页面,实现archive.php的工作。

使用is语法判断模板

$this->is('index');
$this->is('archive');
$this->is('single');
$this->is('page');
$this->is('post');
$this->is('category');
$this->is('tag');
甚至是

$this->is('category', 'default');
$this->is('page', 'start');
$this->is('post', 1);
需要注意的是,后面的参数是分类、页面的缩略名 写法

is('post')) : ?>
这里就是内容了

自定义页面title显示方式

官方默认模板的title(html中的

posted @ 2017-07-24 18:43  WF'S  阅读(1164)  评论(0编辑  收藏  举报