<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="Typecho 搭建博客主题常用代码修改集合">
<p>
作者:<a href="index.php?action=showuser&amp;userid=2&amp;hash=">admin</a><br />时间:2018-05-09 15:34<br />分类:<a href="index.php?action=list&amp;cid=16&amp;hash=">站点建设</a><br />内容:1、Typecho 建站文章摘要显示

熟悉WordPress的用户都应该知道&lt;!--more--&gt;标签，在撰写文章时，Typecho也一样，你可以在文章的正文中插入&lt;!--more--&gt; 标签来创建文章摘要。

2、Typecho 建站首页实现阅读全文

Typecho自动显示摘要，200为自动摘要的字数。



    &lt;p&gt;&lt;?php $this-&gt;excerpt(200); ?&gt;&lt;/p&gt;

    &lt;p class=&quot;more&quot;&gt;&lt;a href=&quot;&lt;?php $this-&gt;permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;&lt;?php $this-&gt;title() ?&gt;&quot;&gt;阅读全文&lt;/a&gt;&lt;/p&gt;




 

3、Typecho 自定义数量标签列表



    &lt;?php $this-&gt;widget('Widget_Metas_Tag_Cloud', array('sort' =&gt; 'count', 'ignoreZeroCount' =&gt; true, 'desc' =&gt; true, 'limit' =&gt; 20))-&gt;to($tags); ?&gt;

    &lt;?php while($tags-&gt;next()): ?&gt;

        &lt;li&gt;

         &lt;a rel=&quot;tag&quot; href=&quot;&lt;?php $tags-&gt;permalink(); ?&gt;&quot; &gt;&lt;?php $tags-&gt;name(); ?&gt;&lt;/a&gt;

        &lt;/li&gt;

    &lt;?php endwhile; ?&gt;




 

4、边栏每月归档后显示文章数目



    &lt;?php $this-&gt;widget('Widget_Contents_Post_Date', 'type=month&amp;format=Y年m月')-&gt;parse('&lt;li&gt;&lt;a href=&quot;{permalink}&quot;&gt;{date}&lt;/a&gt; &lt;span id=&quot;ignore&quot;&gt;({count})&lt;/span&gt;&lt;/li&gt;'); ?&gt;




 

5、显示全部文章列表，可以应用在任何地方



    &lt;?php $this-&gt;widget('Widget_Contents_Post_Recent', 'pageSize=10000')-&gt;parse('&lt;li&gt;{year}-{month}-{day} : &lt;a href=&quot;{permalink}&quot;&gt;{title}&lt;/a&gt;&lt;/li&gt;'); ?&gt;




 

6、 显示上一篇 下一篇



    上一篇&lt;?php $this-&gt;thePrev('&amp;laquo; %s', ''); ?&gt;&lt;br&gt;&lt;br&gt;

    下一篇&lt;?php $this-&gt;theNext('%s &amp;raquo;', ''); ?&gt;




 

7、给网站添加返回顶部按钮

纯js实现返回顶部的功能，适用于任何网页！jquery是调用的谷歌的，国内加载谷歌的较慢，因此推荐使用百度的或新浪的！你也可以将js放到本地服务器！

百度开放云平台：http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs

推荐一个&ldquo;返回顶部代码&rdquo;网站，真心不错！地址：Scroll to Top Button

8、让Typecho侧边栏不显示博主评论，找到sidebar.php文件

将一下代码：



    &lt;?php $this-&gt;widget('Widget_Comments_Recent')-&gt;to($comments); ?&gt;




修改为：



    &lt;?php $this-&gt;widget('Widget_Comments_Recent','ignoreAuthor=true')-&gt;to($comments); ?&gt;




 

9、前台输出相关统计



    &lt;?php Typecho_Widget::widget('Widget_Stat')-&gt;to($stat); ?&gt;

    &lt;p&gt;&lt;?php _e('氪星人自 &lt;strong&gt;2013&lt;/strong&gt; 年建站以来，截至 %s 在设定的 &lt;strong&gt;%s&lt;/strong&gt; 个分类

    和 &lt;strong&gt;%s&lt;/strong&gt; 个页面中，

    发布了 &lt;strong&gt;%s&lt;/strong&gt; 篇文章，收到了 &lt;strong&gt;%s&lt;/strong&gt; 条评论。

    ', date('Y年n月j日G时i分'), $stat-&gt;categoriesNum, $stat-&gt;publishedPagesNum, $stat-&gt;publishedPostsNum, $stat-&gt;publishedCommentsNum); ?&gt;&lt;/p&gt;




 

10、创建自定义首页或页面模板



    &lt;?php

    /**

    * 自定义首页模板

    *

    * @package index

    */

     

    &lt;?php

    /**

    * 自定义页面模板

    *

    * @package custom

    */




 

11、Typecho添加彩色标签云



    &lt;?php Typecho_Widget::widget('Widget_Metas_Tag_Cloud')-&gt;to($tags); ?&gt;

    &lt;?php if($tags-&gt;have()): ?&gt;

    &lt;?php while ($tags-&gt;next()): ?&gt;

    &lt;a style=&quot;color:rgb(&lt;?php echo(rand(0,255)); ?&gt;,&lt;?php echo(rand(0,255)); ?&gt;,

    &lt;?php echo(rand(0,255)); ?&gt;)&quot; href=&quot;&lt;?php $tags-&gt;permalink();?&gt;&quot;&gt;

    &lt;?php $tags-&gt;name(); ?&gt;&lt;/a&gt;

    &lt;?php endwhile; ?&gt;

    &lt;?php endif; ?&gt;




 

12、新窗口打开评论者主页

打开varWidgetAbstract 夹下的 Comments.php 文件，找到这句：



    echo '&lt;a href=&quot;' , $this-&gt;url , '&quot;' , ($noFollow ? ' rel=&quot;external nofollow&quot;' : NULL) , '&gt;' , $this-&gt;author , '&lt;/a&gt;';




修改为：



    echo '&lt;a href=&quot;' , $this-&gt;url , '&quot;' , ($noFollow ? ' rel=&quot;external nofollow&quot;' : NULL) , ' target=&quot;_blank&quot;&gt;' , $this-&gt;author , '&lt;/a&gt;';




13、Typecho添加友情链接（插件）

插件下载：Links.rar   (9.3 KB,  最后修改: 2013-12-08)

使用向导：在侧边栏添加友情链接

最简单的调用方式为：



    &lt;?php Links_Plugin::output(); ?&gt;




如果想限制侧边栏的链接数量，比如说为10个，则可调用：



    &lt;?php Links_Plugin::output(&quot;SHOW_TEXT&quot;, 10); ?&gt;



</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
