首页
留言反馈
网站导航
推荐
毒鸡汤
Search
1
非插件为typecho 文章生成微海报分享
18,938 阅读
2
主题移动端,样式下添加二级分类
15,460 阅读
3
主题 添加author page
14,770 阅读
4
主题添加移动端下边栏
12,779 阅读
5
EMlog添加评论者邮箱等级
9,122 阅读
typecho
dynamic
SuiYu
Emlog
xiuno
登录
/
注册
Search
标签搜索
代码
xiuno
php
css
typecho
评论
模板
say
js
修改教程
标签
珍惜
努力
recommend
善良
样式
调用
微笑
颜色
插件
Vincent
累计撰写
151
篇文章
累计收到
184
条评论
首页
栏目
typecho
dynamic
SuiYu
Emlog
xiuno
页面
留言反馈
网站导航
推荐
毒鸡汤
搜索到
24
篇与
的结果
2020-10-11
为Typecho文章增加HTML标签支持
前言 之前一直用EditorMD插件编辑文章,因为它支持实时预览、代码/表格插入、代码折叠等功能,但是主题自带的目录功能就没法使用了,而且在首页文章预览页面,会出现文章内的Markdown语法,看起来始终让人觉得不够好,另外还不能使用PJAX 无刷新的功能(因为会出现新的bug),所以我就想既然我暂时想要的只是一个折叠功能--也就是解析几个HTML标签,何不换一个思路,停用插件让Typecho支持这几个标签不就好了嘛。解决方法 于是我就上网查了下,原来是如此的简单,只需要在Typecho/var/目录下的HyperDown.php文件的第17行后边自行添加想要的HTML标签就可以了<?php /** * Parser * * @copyright Copyright (c) 2012 SegmentFault Team. (http://segmentfault.com) * @author Joyqi <joyqi@segmentfault.com> * @license BSD License */ class HyperDown { /** * _whiteList * * @var string */ public $_commonWhiteList = 'kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small|details|summary|p'; #这里我已经添加上了<details>|<summary>|<p>这三个想要的标签 /** * _specialWhiteList * * @var mixed * @access private */ public $_specialWhiteList = array( 'table' => 'table|tbody|thead|tfoot|tr|td|th' );
2020年10月11日
1,657 阅读
0 评论
6 点赞
2020-10-09
Typecho实现类似微博几分钟、几天前的词义化时间
在 var/Typecho/I18n.php 代码如下:/** * 词义化时间 * * @access public * @param string $from 起始时间 * @param string $now 终止时间 * @return string */ public static function dateWord($from, $now) { $between = $now - $from; /** 如果是一天 */ if ($between >= 0 && $between < 86400 && date('d', $from) == date('d', $now)) { /** 如果是一小时 */ if ($between < 3600) { /** 如果是一分钟 */ if ($between < 60) { if (0 == $between) { return _t('刚刚'); } else { return str_replace('%d', $between, _n('刚刚', '%d秒前', $between)); } } $min = floor($between / 60); return str_replace('%d', $min, _n('1分钟前', '%d分钟前', $min)); } $hour = floor($between / 3600); return str_replace('%d', $hour, _n('1小时前', '%d小时前', $hour)); } /** 如果是昨天 */ if ($between > 0 && $between < 172800 && (date('z', $from) + 1 == date('z', $now) // 在同一年的情况 || date('z', $from) + 1 == date('L') + 365 + date('z', $now))) { // 跨年的情况 return _t('昨天 %s', date('H:i', $from)); } /** 如果是一个星期以内 */ if ($between > 0 && $between < 604800) { $day = floor($between / 86400); return str_replace('%d', $day, _n('1天前', '%d天前', $day)); } /** 如果是一个星期以上 */ if ($between > 0 && $between < 2592000){ $week = floor($between / 648000); return str_replace('%d', $week, _n('1周前', '%d周前', $week)); } /** 如果是一年以内 */ if ($between > 0 && $between < 31557600){ $month = floor($between / 2629800); return str_replace('%d', $month, _n('1个月前', '%d个月前', $month)); } /** 如果是一年以上 */ if (date('Y', $from) == date('Y', $now)) { return date(_t('Y年n月j日 H:i'), $from); } return date(_t('Y年m月d日 H:i'), $from); }编辑文件→comments.php 找到以下代码<?php $comments->date(); ?>修改为:<?php $comments->dateWord(); ?>
2020年10月09日
2,336 阅读
1 评论
2 点赞
2020-09-29
Typecho基于评论数的评论等级
今天发现了一个 Typecho 的评论等级,感觉很有意思就特地的分享出来了。代码[hide]function dengji($i){ $db=Typecho_Db::get(); $mail=$db->fetchAll($db->select(array('COUNT(cid)'=>'rbq'))->from('table.comments')->where('mail = ?', $i)->where('authorId = ?','0')); foreach ($mail as $sl){ $rbq=$sl['rbq'];} if($rbq<1){ echo 'Boss'; }elseif ($rbq<5 && $rbq>0) { echo '朋友'; }elseif ($rbq<10 && $rbq>=5) { echo '游客'; }elseif ($rbq<15 && $rbq>=10) { echo '游客1'; }elseif ($rbq<20 && $rbq>=15) { echo '游客2'; }elseif ($rbq<25 && $rbq>=20) { echo '游客3'; }elseif ($rbq>=25) { echo '游客4'; } }[/hide]使用方法将以上代码加到functions.php里,然后在comments.php里找到如下位置(可能有的主题不一样):<span class=" <?php echo $commentAuthor; ?> "><?php $comments->author(false); ?>:</span> <?php dengji($comments->mail);?> 在评论列表循环里加上这个引用,也就是这样:<span class=" <?php echo $commentAuthor; ?> ">【<?php dengji($comments->mail);?>】<?php $comments->author(false); ?>:</span>报错如果博主称号显示不是Boss而是游客,那么请在Mysql里执行如下:update typecho_comments set authorid='1' where mail='博主邮箱账号'
2020年09月29日
5,275 阅读
13 评论
8 点赞
2020-09-28
Typecho评论生成随机用户头像
添加代码将下面代码添加到当前主题functions.php中:[hide]/** * 添加随机用户头像 */ function local_random_avatar($user) { $options = Typecho_Widget::widget('Widget_Options'); if($user == 'admin'){ $thumb= $options->themeUrl .'/img/avatar-default.png'; }else{ $thumb= $options->themeUrl .'/img/avatar/' . rand(1, 10) . '.png'; } $avatar = "<img alt='{$user}的头像' src='{$thumb}' class='avatar avatar-50 photo' />"; echo $avatar; }[/hide]使用方法在要调用头像的地方插入:<?php local_random_avatar($comments->author)?>bz的图像不一样显示转载自:拾光分享网
2020年09月28日
2,161 阅读
1 评论
3 点赞
2020-09-28
实现每评论一次自动排第一功能(Typecho版)
下面是主要代码(插入到 functions.php 中):function Autofirst(){ $db = Typecho_Db::get(); $query = $db->select()->from('table.comments')->where('authorId = ?','0')->order('coid',Typecho_Db::SORT_DESC)->limit(100); $result = $db->fetchAll($query); $arrUrl = array(); $arrAuthor = array(); foreach ($result as $value) { if($value["url"]!==null){ array_push($arrUrl,$value["url"]); array_push($arrAuthor,$value["author"]); } } $su=array_filter(array_merge(array_unique($arrUrl))); $sa=array_filter(array_merge(array_unique($arrAuthor))); $num=0; for($i=0;$i<count(array_unique($su));$i++){ if($su[$i]!=="" && $num<16){ $num+=1; $db1 = Typecho_Db::get(); $query1 = $db1->select()->from('table.comments')->where('url = ?',$su[$i])->order('coid',Typecho_Db::SORT_DESC)->limit(100); $result1 = $db1->fetchAll($query1); $arrAuthor1 = array(); foreach ($result1 as $value) { array_push($arrAuthor1,$value["author"]); } echo '<a href="'.$su[$i].'" rel="external nofollow" class="item col-lg-3 col-md-3 visible-lg visible-md" target="_blank"><i class="glyphicon glyphicon-leaf"></i> '.$arrAuthor1[0].'</a>'; } } }调用代码和 css:[hide]<div class="row autofirst visible-lg visible-md"> <p> <i class="glyphicon glyphicon-th"></i> 每评论一次就会自动排在本栏目第一位 </p> <?php Autofirst(100) ?> </div> <style> .autofirst{ margin:20px 20px 5px 20px; padding:10px; box-shadow: 0 1px 8px rgba(0,0,0,0.12), 0 1px 8px rgba(0,0,0,0.24); background-color:white; border-radius:3px; }.item{ padding:5px 0px; } </style>[/hide]
2020年09月28日
4,522 阅读
0 评论
2 点赞
2020-07-13
加载时间
在 functions.php 中加入以下代码: /** * 加载时间 * @return bool */ function timer_start() { global $timestart; $mtime = explode( ' ', microtime() ); $timestart = $mtime[1] + $mtime[0]; return true; } timer_start(); function timer_stop( $display = 0, $precision = 3 ) { global $timestart, $timeend; $mtime = explode( ' ', microtime() ); $timeend = $mtime[1] + $mtime[0]; $timetotal = number_format( $timeend - $timestart, $precision ); $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s"; if ( $display ) { echo $r; } return $r; }然后,在模板中引用:<?php echo timer_stop();?>前台输出相关统计1.<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?> 2.<p><?php _e('氪星人自 <strong>2013</strong> 年建站以来,截至 %s 在设定的 <strong>%s</strong> 个分类 3.和 <strong>%s</strong> 个页面中, 4.发布了 <strong>%s</strong> 篇文章,收到了 <strong>%s</strong> 条评论。 5.', date('Y年n月j日G时i分'), $stat->categoriesNum, $stat->publishedPagesNum, $stat->publishedPostsNum, $stat->publishedCommentsNum); ?></p>文章字数统计在主题的functions.php中写入代码: function art_count ($cid){ $db=Typecho_Db::get (); $rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1)); echo mb_strlen($rs['text'], 'UTF-8'); } 然后在想要添加的地方之间加调用就ok <?php echo art_count($this->cid); ?>总访客数统计代码 functions.php 中,添加以下统计代码//总访问量 function theAllViews() { $db = Typecho_Db::get(); $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`'); echo number_format($row[0]['SUM(VIEWS)']); } 然后在你需要显示的位置(如:footer.php sidebar.php 等)插入以下调用代码 <?php echo theAllViews();?></span><?php _me("访客总数") ?>添加版权声明<blockquote> <strong>本文作者:</strong><a target="_blank" href="https://www.2025ly.com">ly's Blog</a> <br><br> <strong>本文链接:</strong><a target="_blank" href="<?php $this->permalink() ?>"><?php $this->title() ?> - <?php $this->permalink() ?></a> <br><br> <strong>版权声明:</strong>如无特别声明,本文即为原创文章,仅代表个人观点,版权归 <a href="<?php $this->options->siteUrl(); ?>" target="_blank"><?$this->options->title();?></a> 所有,未经允许不得转载! </blockquote>
2020年07月13日
3,371 阅读
2 评论
2 点赞
1
2
3