CODESHIF - Typecho http://codeshif.com/category/typecho/ Typecho技巧 Typecho显示文章阅读次数统计 http://codeshif.com/archives/61.html 2021-11-24T16:42:41+08:00 控制台 / 外观 / 编辑当前外观 / 在 functions.php 最后面加入以下代码代码已中加入了cookie验证,让文章浏览次数更具有真实性function get_post_view($archive) { $cid = $archive->cid; $db = Typecho_Db::get(); $prefix = $db->getPrefix(); if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); echo 0; return; } $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); if ($archive->is('single')) { $views = Typecho_Cookie::get('extend_contents_views'); if(empty($views)){ $views = array(); }else{ $views = explode(',', $views); } if(!in_array($cid,$views)){ $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); array_push($views, $cid); $views = implode(',', $views); Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie } } echo $row['views']; }在需要显示次数的地方 (如 index.php,post.php) 加入下边的代码阅读 <?php get_post_view($this) ?> Typecho自定义首页文章数量 http://codeshif.com/archives/44.html 2021-11-24T14:47:23+08:00 修改typecho首页显示文章的数量:编辑文件 functions.php在末尾添加:/* 自定义首页文章分布数量,如 10 */ function themeInit($archive) { if ($archive->is('index')) { $archive->parameter->pageSize = 10; } } Typecho导航栏输出分类 http://codeshif.com/archives/43.html 2021-11-24T14:08:47+08:00 编辑外观文件header.php搜索<?php _e('首页'); ?></a>在空行后面添加<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?> <?php while($categories->next()): ?> <a<?php if($this->is('category', $categories->slug)): ?> class="current"<?php endif; ?> href="<?php $categories->permalink(); ?>" title="<?php $categories->name(); ?>"><?php $categories->name(); ?></a> <?php endwhile; ?> Typecho伪静态Rewrite设置 http://codeshif.com/archives/5.html 2018-10-18T01:38:00+08:00 在站点根目录写文件.htaccess文件,然后写入以下内容,并在设置中开启永久链接即可!<IfModule mod_rewrite.c> RewriteEngine On #如果开启了HTTPS服务,使用以下两行内容 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R=301] #开启伪静态 RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] &lt;/IfModule&gt; Typecho首页显示文章摘要的方法 http://codeshif.com/archives/4.html 2018-10-18T00:53:00+08:00 Typecho博客默认文章没有自动摘要的功能,首页和分类归档页面显示的文章都是全文输出的。不爽?那就登录到后台-控制台-外观-编辑当前外观:编辑文件 index.php找到:<?php $this->content('- 阅读剩余部分 -'); ?>替换成:<?php $this->excerpt(300,'- 阅读剩余部分 -'); ?>300这个数字,你怎么开心,怎么设置。还有个好方法:编辑文件/var/Widget/Abstract/Contents.php改成这样:/** * 输出文章摘要 * * @access public * @param integer $length 摘要截取长度 * @param string $trim 摘要后缀 */ public function excerpt($length = 100, $trim = '...') { // Typecho_Common::subStr(strip_tags($this->excerpt), 0, $length, $trim) echo Typecho_Common::subStr(strip_tags($this->excerpt), 0, $length, $trim) . "<p class=\"more\"><a href=\"{$this->permalink}\" title=\"{$this->title}\">- 阅读剩余部分 -</a></p>"; }