typecho是一款不错的轻量化博客系统,圈子里也拥有众多爱好者。博客除了后台的发布功能之外,最重要的算得上是博客的外观了,别人的制作的主题可能有时候不怎么符合自身需求或者使用习惯。这时候就有必要了解一下主题小修改或者进行一下个性化的改造。以满足自身需求。

文章title设置

实现方法一

博客首页 —> 博客名称 - 博客描述 归档页面 —> XXXX/XX - 博客名称 文章页面 —> 文章标题 - 博客名称 独立页面 —> 页面标题 - 博客名称 分类页面 —> 分类名称 - 博客名称 标签页面 —> 标签 - 博客名称

1<title>
2<?php if($this->is('index')): ?><?php $this->options->title(); ?>-<?php $this->options->description(); ?>
3<?php elseif($this->is('archive')): ?><?php $this->archiveTitle('/','',' - '); ?><?php $this->options->title(); ?>
4<?php else: ?><?php $this->archiveTitle('','',' - '); ?><?php $this->options->title(); ?><?php endif; ?>
5</title>

实现方法二

博客首页 —> 博客名称 独立页面 —> 页面标题 - 博客名称 分类页面 —> 分类名称 - 博客名称 标签页面 —> Tag: 标签 - 博客名称 存档页面 —> 存档: XXXX年XX月 - 博客名称 其它(日志页)—> 页面标题

1<title>
2<?php if ($this->is('index')){$this->options->title();}
3elseif($this->is('page')){$this->archiveTitle('','',' - ');$this->options->title();}
4elseif($this->is('category')){$this->archiveTitle('','',' - ');$this->options->title();}
5elseif($this->is('tag')){$this->archiveTitle('','Tag: ',' - ');$this->options->title();}
6elseif($this->is('archive')){$this->archiveTitle('年','存档: ','月 - ');$this->options->title();}
7else{$this->archiveTitle('','','');}?>
8</title>

默认的实例

1<?php $this->archiveTitle('',  '',  ' - ');  ?><?php $this->options->title();  ?>-<?php $this->options->description();  ?>

相关文章调用

 1<?php $this->related(5)->to($relatedPosts); ?>
 2<?php if ($relatedPosts->have()): ?>
 3<?php while ($relatedPosts->next()): ?>
 4<li>
 5<a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a> <small class="info"><strong><?php $relatedPosts->author(); ?></strong> post in<?php $this->date('Y-m-d H:i:s'); ?></small>
 6</li>
 7<?php endwhile; ?>
 8<?php else : ?>
 9<li>No Related Post</li>
10<?php endif; ?>

输出Tags

1<?php $this->widget('Widget_Metas_Tag_Cloud') ->parse('<span class="tagcloud"><a href="{permalink}">{name}</span></a>'); ?>

分页只显示新文章、旧文章

1<?php $this->pageLink('? 新文章','prev'); ?>
2<?php $this->pageLink('旧文章 ?','next'); ?>

测边栏每月归档后面显示文章数

1<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=Y年m月')
2->parse('<li><a href="{permalink}">{date}</a> <span id="ignore">({count})</span></li>'); ?>

复制文章时带版权

实例一

 1<script type="text/javascript">
 2    function copy_code(text) {
 3        if (window.clipboardData) {
 4        window.clipboardData.setData("Text", text)
 5            alert("已经成功复制到剪贴板!");
 6        } else {
 7        var x=prompt('你的浏览器可能不能正常复制\n请你手动进行:',text);
 8        }
 9        //return false;
10    }
11</script>

实例二

 1< script type = "text/javascript" >
 2    document.body.oncopy = function () {
 3        setTimeout(function () {
 4            var text = clipboardData.getData("text");
 5            if (text) {
 6                text = text +
 7                    "\r\n本篇文章来源于<?php $this->options->title(); ?>|<?php $this->options->siteUrl(); ?>,原文链接:" +
 8                    location.href;
 9                clipboardData.setData("text", text);
10            }
11        }, 100)
12    } <
13    /script

标签云

1<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=20′)->to($tags); ?>
2<?php while($tags->next()): ?>
3<a href=”<?php $tags->permalink(); ?>”><?php $tags->name(); ?></a>
4<?php endwhile; ?>

最新文章

1<?php $this->widget('Widget_Contents_Post_Recent')->to($post); ?>
2<?php while($post->next()): ?>
3<a href=”<?php $post->permalink(); ?>” title=”<?php $post->title(); ?>”>
4<?php $post->title(25, '…'); ?></a>
5<?php endwhile; ?>

相关内容

1<?php $this->related(5)->to($relatedPosts); ?>
2<?php while ($relatedPosts->next()): ?>
3<a href=”<?php $relatedPosts->permalink(); ?>” title=”
4<?php $relatedPosts->title(); ?>”><?php $relatedPosts->title(); ?></a>
5<small><strong><?php $relatedPosts->author(); ?></strong> post in
6<?php $this->date('Y-m-d H:i:s'); ?></small>
7<?php endwhile; ?>

日期归档显示统计数量

1<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')->parse('<li><a href=”{permalink}”>{date}</a> ({count})</li>'); ?>

友情链接 要安装插件

1<?php PageToLinks::output('links', 'h3', 'ul'); ?>

头部关键信息

 1<?php $this->keywords('_'); ?> //关键词
 2<?php $this->options->title(); ?> //站点名称
 3<?php $this->options->description(); ?> //站点描述
 4<?php $this->archiveTitle(); ?> //标题
 5<?php $this->options->themeUrl('ie.css'); ?> //模板路径
 6<?php $this->options->siteUrl(); ?> //主页网址
 7<?php $this->options->feedUrl(); ?>
 8<?php $this->options->commentsFeedUrl(); ?>
 9<?php $this->pageNav(); ?> //分页
10<?php $this->options->generator(); ?> //版本号

文章页面相关参数调用

1<?php $this->title(); ?> //标题
2<?php $this->category(','); ?> //分类
3<?php $this->tags(', ', true, ''); ?> //标签
4<?php $this->date('F jS, Y') ?> //时间
5<?php $this->content(); ?> //内容
6<?php $this->thePrev('&laquo; %s', ''); ?> //上一篇
7<?php $this->theNext('%s &raquo;', ''); ?> //下一篇

全部文章列表代码

1<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->parse('<li>{year}-{month}-{day} : <a href="{permalink}">{title}</a></li>'); ?>

全部标签集列表

1<?php $this->widget('Widget_Metas_Tag_Cloud')
2     ->to($taglist); ?><?php while($taglist->next()): ?>
3<li><a href="<?php $taglist->permalink(); ?>" title="<?php $taglist->name(); ?>"><?php $taglist->name(); ?></a></li>
4<?php endwhile; ?>

全部日志数量

1<?php $stat = Typecho_Widget::widget('Widget_Stat') ;echo ".$stat->PublishedPostsNum."; ?>

评论输出

1<?php $comments->author(true); ?>//输出评论人昵称,参数true为带链接的,false为不带链接的;
2//ps.其实还有一个参数,类型也是布尔,作用是是否带noFollow
3<?php $comments->excerpt(18, '...'); ?>//输出评论摘要,第一个参数是要截取的长度,第二个是截取后的字符串;
4<?php $comments->permalink(); ?>//获取当前评论链接,木有参数;
5<?php $comments->title(); ?>//获取当前评论标题,同样木有参数;
6<?php $comments->dateWord(); ?>//输出词义化日期,就是输出“3小时前”、“三天前”之内的;
7<?php $comments->gravatar(); ?>//调用gravatar输出用户头像,有两个参数,第一个是头像尺寸,默认是32,第二个是默认输出

Typecho文章标题字数限制

1<?php $this->widget('Widget_Contents_Post_Recent')->to($post); ?>
2<?php while($post->next()): ?>
3<li><a href="<?php $post->permalink(); ?>"><?php $post->title(25, '...'); ?></a></li>
4<?php endwhile; ?>

侧栏评论忽略博主评论

1<?php $this->widget('Widget_Comments_Recent','ignoreAuthor=true')->to($comments); ?>

调用某分类文章,pageSize是数量,mid是分类号

1<?php $this->widget('Widget_Archive@index', 'pageSize=6&type=category', 'mid=1')
2   ->parse('<li><a href="{permalink}">{title}</a></li>'); ?>

typecho自动显示摘要

1<?php $this->excerpt(180); ?>

分离文章的评论和引用通告

打开模板的 comments.php 文件,找到通篇的核心语句

1<?php $this->comments()->to($comments); ?>

这条语句控制着评论的类型,他的参数如下

1<?php $this→comments()→to($comments); ?>  显示全部(默认) 
2<?php $this→comments('comment')→to($comments); ?>  只显示 comment 
3<?php $this→comments('trackback')→to($trackbacks); ?>  只显示 trackback 
4<?php $this→comments('pingback')→to($pingbacks); ?>  只显示 pingback 

为了分开,我们开始对 comments.php 做如下修改,首先只显示评论

 1<?php $this->comments('comment')->to($comments); ?>
 2<?php if ($comments->have()) : ?>
 3 <ol>
 4 <?php while ($comments->next()) : ?>
 5 <li id="<?php $comments->theId() ?>">
 6  <div class="comment_data">
 7   <?php $comments->gravatar(32, '', '', 'avatar'); ?>
 8   <span><?php $comments->author() ?></span> Says:<br />
 9   <?php $comments->date('F jS, Y'); ?> at <?php $comments->date('h:i a'); ?>
10  </div>
11  <div class="comment_text"><?php $comments->content() ?></div>
12 </li>
13 <?php endwhile; ?>
14 </ol>
15<?php endif; ?>

然后输出 pingback,pingback 并不需要那么多的展示内容,假设只展示标题和日期

 1<?php $this->comments('pingback')->to($pingbacks); ?><!-- 关键 -->
 2<?php if ($pingbacks->have()) : ?>
 3 <h3>Pingbacks</h3>
 4 <ol>
 5 <?php while ($pingbacks->next()) : ?>
 6  <li id="<?php $pingbacks->theId() ?>">
 7   <?php $pingbacks->author() ?> <?php $pingbacks->date('F jS, Y'); ?>
 8  </li>
 9 <?php endwhile; ?>
10 </ol>
11<?php endif; ?>