被遗忘的角落
这里有一些制作 Typecho 主题时常用的代码。所有这些技巧都收集自 typecho 论坛,我整理出来一是为了自己日后方便查阅,二是为有需要的朋友提供便利。
1、文章title设置,使得对搜索引擎足够友好,下面是本博的设置方法 【博客首页】---> 博客名称 - 博客描述 【归档页面】---> XXXX/XX - 博客名称 【文章页面】---> 文章标题 - 博客名称 【独立页面】---> 页面标题 - 博客名称 【分类页面】---> 分类名称 - 博客名称 【标签页面】---> 标签 - 博客名称<title><?php if($this->is('index')): ?><?php $this->options->title(); ?> - <?php $this->options->description(); ?>
<?php elseif($this->is('archive')): ?><?php $this->archiveTitle('/','',' - '); ?><?php $this->options->title(); ?>
<?php else: ?><?php $this->archiveTitle('','',' - '); ?><?php $this->options->title(); ?><?php endif; ?></title>附论坛的两种不同的设置:
【博客首页】博客名称
【独立页面】页面标题 - 博客名称
【分类页面】分类名称 - 博客名称
【标签页面】Tag: 标签 - 博客名称
【存档页面】存档: XXXX年XX月 - 博客名称
【其它(日志页)】页面标题<title>
<?php if ($this->is('index')){$this->options->title();}
elseif($this->is('page')){$this->archiveTitle('','',' - ');$this->options->title();}
elseif($this->is('category')){$this->archiveTitle('','',' - ');$this->options->title();}
elseif($this->is('tag')){$this->archiveTitle('','Tag: ',' - ');$this->options->title();}
elseif($this->is('archive')){$this->archiveTitle('年','存档: ','月 - ');$this->options->title();}
else{$this->archiveTitle('','','');}?>
</title><title><?php $this->archiveTitle('', '', ' - '); ?><?php $this->options->title(); ?> - <?php $this->options->description(); ?></title>2、相关文章的调用:<?php $this->related(5)->to($relatedPosts); ?>
<?php if ($relatedPosts->have()): ?>
<?php while ($relatedPosts->next()): ?>
<li>
<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>
</li>
<?php endwhile; ?>
<?php else : ?>
<li>No Related Post</li>
<?php endif; ?>3、输出所有Tags<?php $this->widget('Widget_Metas_Tag_Cloud')
->parse('<span class="tagcloud a5 b1"><a href="{permalink}">{name}</span></a>'); ?>4、分页只显示新文章、旧文章<?php $this->pageLink('« 新文章','prev'); ?>
<?php $this->pageLink('旧文章 »','next'); ?>5、测边栏每月归档后面显示文章数<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=Y年m月')
->parse('<li><a href="{permalink}">{date}</a> <span id="ignore">({count})</span></li>'); ?>6、复制文章时带版权<script type="text/javascript">
document.body.oncopy = function () { setTimeout( function () { var text = clipboardData.getData("text"); if (text) { text = text + "\r\n本篇文章来源于<?php $this->options->title(); ?>|<?php $this->options->siteUrl(); ?>,原文链接:"+location.href; clipboardData.setData("text", text); } }, 100 ) }
</script>
[...]转载以备不时之需:Typecho主题制作常用代码[...]
2011-10-12 14:31 回复很好,学习了
2011-05-04 13:33 回复这个代码由颜色是怎么显示的呢
2010-09-13 16:40 回复你好,这是一个插件:Simple Code ,你可以去TE园地搜索。
2010-09-14 00:58smarty忠实粉丝路过~
2010-08-18 22:13 回复代码应该是通用的吧。
2010-08-13 00:31 回复You are right.
2010-08-13 00:33我也加好了 我的空间商不让我开留言板 评论还得审核 太恶心了
2010-08-09 11:19 回复啊~我的博客已经出国好久了,呵呵
2010-08-10 23:44汗,我一直以为你用的是WP。。。
2010-08-09 03:56 回复typecho 借鉴了不是 wp的东西
2010-08-15 13:55呵呵,是 Typecho.
2010-08-10 23:40交换连接 哈哈 西瓜回来了 你们都换WP了 我换了几天还是BO用的舒服
2010-08-08 21:55 回复欢迎归来,我从BOB 转到 Typecho 了,不是wp,wp太臃肿了,不喜欢,呵呵,链接已经加上,欢迎常来。
2010-08-08 22:41