菜单
控制台
概要
个人设置
插件
外观
编辑文件 functions.php
备份
撰写
撰写文章
创建页面
管理
文章
独立页面
评论
分类
标签
文件
用户
友情链接
设置
基本
评论
阅读
永久链接
测试管理员
登出
网站
编辑文件 functions.php
可以使用的外观
编辑
Massive
外观
设置外观
编辑源码
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; function themeConfig($form) { echo "<style>code {background: #222;padding: 2px;color: #fff;margin: 0 5px;}</style>"; $edit = new Typecho_Widget_Helper_Form_Element_Text('zdgg', NULL, _t('承接一切烂主题制作'), _t('站点公告'), _t('在这里填入站点公告')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Textarea('author', NULL, _t("请到后台修改作者简介\n- Massive"), _t('作者简介'), _t('在这里填入作者简介')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Text('copyright', NULL, _t('© {{year}} {{site}} & All Rights Reserved .'), _t('页脚文本'), _t('<code>{{year}}</code>代表当前年份,<code>{{site}}</code>代表站点')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Textarea('widgets', NULL, _t("author\r\nlatest-posts\r\nsocial\r\ncategory\r\nlatest-comments\r\ntags"), _t('边栏模块'), _t('一行一个,可选<code>author|latest-posts|social|category|latest-comments|tags</code>')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Textarea('social', NULL, _t("facebook,#\r\ntwitter,#\r\ndribbble,#\r\ngoogle-plus,#\r\nbehance,#\r\nenvelope-o,mailto:typecho.re@woai.ru"), _t('社交链接'), _t('一行一个,格式<code>图标,链接</code>')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Radio('syzy', array('enable' => _t('显示'), 'disable' => _t('隐藏'), ), 'disable', _t('文章摘由'), _t('首页文章摘要,默认不显示’')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Textarea('postad', NULL, _t("<center><a href='http://www.typecho.re/' target='_blank' title='Typecho 热门主题大全'><img src='https://i.loli.net/2017/12/10/5a2caadf7d9fa.png'/></a></center>"), _t('文章底部广告代码'), _t('支持HTML')); $form->addInput($edit); $edit = new Typecho_Widget_Helper_Form_Element_Textarea('pagead', NULL, _t("<center><a href='http://www.typecho.re/' target='_blank' title='Typecho 热门主题大全'><img src='https://i.loli.net/2017/12/10/5a2caadf7d9fa.png'/></a></center>"), _t('页面底部广告代码'), _t('支持HTML')); $form->addInput($edit); } function themeFields($form) { $edit = new Typecho_Widget_Helper_Form_Element_Text('thumb', NULL, '', '自定义缩略图', 'URL格式,不裁剪'); $form->addItem($edit); } /* * 获取文章浏览次数(改进版) */ function get_post_view($widget, $format = "{views}") { $fields = unserialize($widget->fields); if (array_key_exists('views', $fields)) $views = (!empty($fields['views'])) ? intval($fields['views']) : 0; else $views = 0; //增加浏览次数 if ($widget->is('single')) { $vieweds = Typecho_Cookie::get('contents_viewed'); if (empty($vieweds)) $vieweds = array(); else $vieweds = explode(',', $vieweds); if (!in_array($widget->cid, $vieweds)) { $views = $views + 1; $widget->setField('views', 'str', strval($views), $widget->cid); $vieweds[] = $widget->cid; $vieweds = implode(',', $vieweds); Typecho_Cookie::set("contents_viewed",$vieweds); } } _e(str_replace("{views}", $views, $format)); } /*Typecho 24小时发布文章数量*/ function get_recent_posts_number($days = 1,$display = true) { $db = Typecho_Db::get(); $today = time() + 3600 * 8; $daysago = $today - ($days * 24 * 60 * 60); $total_posts = $db->fetchObject($db->select(array('COUNT(cid)' => 'num')) ->from('table.contents') ->orWhere('created < ? AND created > ?', $today,$daysago) ->where('type = ? AND status = ? AND password IS NULL', 'post', 'publish'))->num; if($display) { echo $total_posts; } else { return $total_posts; } } //热门文章(评论最多) function rmcp($days = 30,$num = 5){ $defaults = array( 'before' => '', 'after' => '', 'xformat' => '<a class="list-group-item visible-lg" title="{title}" href="{permalink}" rel="bookmark"><i class="fa fa-book"></i> {title}</a> <a class="list-group-item visible-md" title="{title}" href="{permalink}" rel="bookmark"><i class="fa fa-book"></i> {title}</a>' ); $time = time() - (24 * 60 * 60 * $days); $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('created >= ?', $time) ->where('type = ?', 'post') ->limit($num) ->order('commentsNum',Typecho_Db::SORT_DESC); $result = $db->fetchAll($sql); echo $defaults['before']; foreach($result as $val){ $val = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($val); echo str_replace(array('{permalink}', '{title}', '{commentsNum}'), array($val['permalink'], $val['title'], $val['commentsNum']), $defaults['xformat']); } echo $defaults['after']; } //随机文章 function theme_random_posts(){ $defaults = array( 'number' => 6, 'before' => '', 'after' => '', 'xformat' => '<a class="list-group-item visible-lg" title="{title}" href="{permalink}" rel="bookmark"><i class="fa fa-book"></i> {title}</a> <a class="list-group-item visible-md" title="{title}" href="{permalink}" rel="bookmark"><i class="fa fa-book"></i> {title}</a>' ); $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('status = ?','publish') ->where('type = ?', 'post') ->where('created <= unix_timestamp(now())', 'post') //添加这一句避免未达到时间的文章提前曝光 ->limit($defaults['number']) ->order('RAND()'); $result = $db->fetchAll($sql); echo $defaults['before']; foreach($result as $val){ $val = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($val); echo str_replace(array('{permalink}', '{title}'),array($val['permalink'], $val['title']), $defaults['xformat']); } echo $defaults['after']; } /** * 取缩略图 * * @access public * @param Widget_Archie $widget * @param mixed $size * @param mixed $link * @return String **/ function showThumb($widget, $link = false){ $thumb = ''; preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $widget->content, $matches ); $options = Typecho_Widget::widget('Widget_Options'); $attach = $widget->attachments(1)->attachment; if (isset($attach->isImage) && $attach->isImage == 1){ $thumb = $attach->url; }elseif(isset($matches[1][0])){ $thumb = $matches[1][0]; } if(array_key_exists('thumb',unserialize($widget->fields))){ $thumb = $widget->fields->thumb; } $thumb = empty($thumb) ? $options->themeUrl . '/img/'.mt_rand(0,14).'.jpg' : $thumb; if(empty($thumb)) return ''; if($link){ return $thumb; } else { return '<img src="' . $thumb .'" />'; } } //获取边栏模块 function massive_get_widget($part) { $DIR_SEP = DIRECTORY_SEPARATOR; $part = ($part == "") ? "-none" : "-".$part; $template = file_exists( dirname(__FILE__).$DIR_SEP.'widgets'.$DIR_SEP.'widget'.$part.".php") ? "widgets".$DIR_SEP."widget".$part.".php" : "widgets".$DIR_SEP."widget-none.php"; return $template; } ?>
保存文件
模板文件
404.php
archive.php
comments.php
footer.php
functions.php
header.php
index.php
page.php
page_no_sidebar.php
post.php
sidebar.php
Typecho
由
Typecho
强力驱动, 版本 1.2.1
帮助文档
•
支持论坛
•
报告错误
•
资源下载