首页
关于
友情链接
归档
更多
统计
推荐
恋爱清单
Search
1
PS没法保存而显示该文件被锁定解决方法
4,875 阅读
2
PHP实现自动提交百度普通收录/SEO
1,125 阅读
3
Open-TDP 多云资源管理系统介绍
1,048 阅读
4
Typecho开启Gzip,感受火箭般速度
935 阅读
5
字节巨量广告平台学习期/保障期介绍
585 阅读
学习
项目
折腾
SEM
excel学习
typecho
登录
Search
标签搜索
typecho
PHP
SEM学习笔记
sem
docker
js
ocpc
Linux
linux笔记
腾讯云
雷池waf
openTDP
CDN
巨量
CPC
雷池
宝塔
百度SEO
photoshop
PS
小唐
累计撰写
76
篇文章
累计收到
0
条评论
首页
栏目
学习
项目
折腾
SEM
excel学习
typecho
页面
关于
友情链接
归档
统计
推荐
恋爱清单
搜索到
15
篇与
typecho
的结果
2023-05-15
typecho主题开发中常用的函数(更新版)
本文收集一些在typecho主题开发中常用的函数,并不断更新。typecho输出文章缩略图/** 输出文章缩略图 */ function showThumbnail($widget) { // 当文章无图片时的默认缩略图 $rand = rand(1,5); // 随机 1-5 张缩略图 $random = $widget->widget('Widget_Options')->themeUrl . '/img/' . $rand . '.jpg'; // 随机缩略图路径 // $random = $widget->widget('Widget_Options')->themeUrl . '/img/mr.jpg'; // 若只想要一张默认缩略图请删除本行开头的"//" $attach = $widget->attachments(1)->attachment; $pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i'; if (preg_match_all($pattern, $widget->content, $thumbUrl)) { echo $thumbUrl[1][0]; } else if ($attach->isImage) { echo $attach->url; } else { echo $random; } }调用方法<?php showThumbnail($this); ?>typecho输出随机文章class Widget_Contents_Post_Rand extends Widget_Abstract_Contents { public function execute() { $this->parameter->setDefault(array('pageSize' => $this->options->postsListSize)); $this->db->fetchAll($this->select() ->where('table.contents.status = ?', 'publish') ->where('table.contents.created options->time) ->where('table.contents.type = ?', 'post') ->order('RAND()', Typecho_Db::SORT_DESC) ->limit($this->parameter->pageSize), array($this, 'push')); } }调用方法<?php $this->widget('Widget_Contents_Post_Rand','pageSize=10')->to($Rand);while($Rand->next()): ?>Title增加副标题<?php if ($this->is('index')): ?> - 副标题<?php endif; ?> 分页标题<title><?php if($this->_currentPage>1) echo '第 '.$this->_currentPage.' 页 - '; ?><?php $this->archiveTitle(' » ', '', ' - '); ?><?php $this->options->title(); ?></title> typecho输出相关文章<?php $this->related(5)->to($relatedPosts); ?> <ul> <?php while ($relatedPosts->next()): ?> <li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li> <?php endwhile; ?> </ul>文章阅读量统计在 模板文件functions.php 中加入下面代码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')) { $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); } echo $row['views']; }调用方法<?php get_post_view($this) ?>
2023年05月15日
127 阅读
0 评论
0 点赞
2023-05-15
typecho主题开发 — 巧妙运用时间处理库Day.js(轻量级,拿来就能用)
什么是Day.js?它是一个极简的JavaScript库,可以为现代浏览器解析、验证、操作和显示日期和时间。,文件大小只有2KB左右,下载、解析js更少。Day.js使用实战今天改主题时候发现原主题的js太笨重了,看着有点眼花(ps:主要是一直在重复造轮子)网上找了下最好的解决办法就是用时间处理库dayjs,一开始我也想过用moment.js,但是moment太大了这个主题用到的东西不多,Dayjs刚刚好。主题代码分析原主题统计网站运用日期jsfunction show_date_time(){ window.setTimeout("show_date_time()", 1000); BirthDay=new Date("2001-1-1"); <!-- 网站运行时间 --> today=new Date(); timeold=(today.getTime()-BirthDay.getTime()); sectimeold=timeold/1000 secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000 e_daysold=timeold/msPerDay daysold=Math.floor(e_daysold); e_hrsold=(e_daysold-daysold)*24; hrsold=Math.floor(e_hrsold); e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); span_dt_dt.innerHTML='已运行 <font style=color:#C40000>'+daysold+'</font> 天 <font style=color:#C40000>'+hrsold+'</font> 时 <font style=color:#C40000>'+minsold+'</font> 分<!--<font style=color:#C40000>'+seconds+'</font> 秒-->'; } show_date_time();用了dayjs后 let qingrenjie = dayjs().diff(dayjs('<2001-1-1'), 'days') document.getElementById('begin_time').innerHTML = qingrenjie原生的js差不多快20行了,用来插件后的只需2行代码看着也简洁很多,这个主题中要用到很多倒计时的功能(!重复造轮子),为了方便看的不花用dayjs是最好的选择。在dayjs中有很多的函数是我们经常可以用到的1)初始化日期 / 时间dayjs().format('YYYY-MM-DD'); // 初始化日期 dayjs().format('YYYY-MM-DD HH:mm:ss'); // 初始化日期时间 2)式化日期 / 时间dayjs(value).format('YYYY-MM-DD'); // 初始化日期 dayjs(value).format('YYYY-MM-DD HH:mm:ss'); // 初始化日期时间 3)加 / 减dayjs().add / dayjs().subtract 代表在当前时间上去加减;dayjs(value).add / dayjs(value).subtract 代表在指定时间(value)上去加减;dayjs().add(7, 'day').format('YYYY-MM-DD'); // 2023-05- 8 今天(2023-05-15)加上7天 dayjs().add(1, 'month').format('YYYY-MM-DD'); // 2023-06-15 今天(2023-05-15)加上一月 dayjs().subtract(2, 'year').format('YYYY-MM-DD'); // 2021-05-15 今天(2023-05-15)减去2年 dayjs().subtract(2, 'hour').format('YYYY-MM-DD HH:mm:ss'); // 2023-05-15 18:00:00 今天现在(2023-05-15 20:00:00)减去2小时4)计算日期dayjs().diff(dayjs('2023-5-14'), 'days') //当前日期 - dayjs()中的日期5)参考当前时间 dayjs() 时间字符串 dayjs('2018-06-03') 时间戳 dayjs(1528361259484) Date 对象 dayjs(new Date(2018,8,18)) 复制 dayjs().clone() 检测当前 Dayjs 对象是否是一个有效的时间 dayjs().isValid() 获取 年 : dayjs().year() 月 : dayjs().month() 日 : dayjs().date() 星期 : dayjs().day() 时 : dayjs().hour() 分 : dayjs().minute() 秒 : dayjs().second() 毫秒 : dayjs().millisecond() 设置 dayjs().set('year',2017) dayjs().set('month',9) 增加时间并返回一个新的 Dayjs() 对象 dayjs().add(7, 'day') dayjs().add(7, 'year') 减少时间并返回一个新的 Dayjs() 对象 dayjs().subtract(7, 'year') dayjs().subtract(7, 'month') 返回当前时间的开头时间的 Dayjs() 对象,如月份的第一天。 dayjs().startOf('year') dayjs().startOf('month') 返回当前时间的末尾时间的 Dayjs() 对象,如月份的最后一天。 dayjs().endOf('month') dayjs().endOf('year') 格式化 dayjs().format() dayjs().format('YYYY-MM-DD dddd HH:mm:ss.SSS A') 时间差 dayjs('2018-06-08').diff(dayjs('2017-06-01'),'years') dayjs('2018-06-08').diff(dayjs('2017-06-01'),'day') dayjs('2018-06-08').diff(dayjs('2017-06-01'),'hour') Unix 时间戳 (毫秒) dayjs().valueOf() Unix 时间戳 (秒) dayjs().unix() 返回月份的天数 dayjs().daysInMonth() 返回原生的 Date 对象 dayjs().toDate() 返回包含时间数值的数组 dayjs().toArray() 当序列化 Dayjs 对象时,会返回 ISO8601 格式的字符串 dayjs().toJSON() //2018-06-08T02:44:30.599Z 返回 ISO8601 格式的字符串 dayjs().toISOString() //2018-06-08T02:46:06.554Z 返回包含时间数值的对象 dayjs().toObject() 字符串 dayjs().toString() 检查一个 Dayjs 对象是否在另一个 Dayjs 对象时间之前 dayjs('2018-06-01').isBefore(dayjs('2018-06-02')) 检查一个 Dayjs 对象是否和另一个 Dayjs 对象时间相同 dayjs().isSame(dayjs()) 检查一个 Dayjs 对象是否在另一个 Dayjs 对象时间之后 dayjs().isAfter(dayjs()) 本文只是我一个学习过程的文章,后续本文会一直更新
2023年05月15日
179 阅读
0 评论
1 点赞
2023-05-15
typecho主题开发— typecho获取文章缩略图,随机图
前言用Brave勇敢爱主题很多年了,原开源作者是免费的,在作者看到有人美化了一下就开价52块钱(ps:比我之前买handsome的主题还要贵)还在博客说今年的520过后就涨价到99,看了下对方的源代码写的不是很好,感觉不值这个加钱,我还是自己重新改下在开源吧,等空的时候也把小程序也弄出来。网上写获取文章缩略图的文章不是很多,这里记录一下今天在主题中添加的代码function img_postthumb($thumbThis) { $db = Typecho_Db::get(); $rs = $db->fetchRow($db->select('table.contents.text') ->from('table.contents') ->where('table.contents.cid=?', $thumbThis->cid) ->order('table.contents.cid', Typecho_Db::SORT_ASC) ->limit(1)); preg_match_all('/\<img.*?src\=\"(.*?)\"[^>]*>/i', $rs['text'], $thumbUrl); //通过正则式获取图片地址 preg_match_all('/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|png))/i', $rs['text'], $patternMD); //通过正则式获取图片地址 preg_match_all('/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|png))/i', $rs['text'], $patternMDfoot); //通过正则式获取图片地址 if(count($thumbUrl[0])>0){ return $thumbUrl[1][0]; //当找到一个src地址的时候,输出缩略图 }else if(count($patternMD[0])>0){ return $patternMD[1][0]; }else if(count($patternMDfoot[0])>0){ return $patternMDfoot[1][0]; }else{ //在主题根目录下的 /img 目录下放随机图片 thumb_开头 //如:thumb_1.jpg return $thumbThis->widget('Widget_Options')->themeUrl."/img/thumb_".rand(1,7).".jpg"; } }` 文件调用方式<?php echo img_postthumb($this); ?>
2023年05月15日
179 阅读
0 评论
0 点赞
2023-05-13
Typecho纯代码添加浏览量代码
Typecho 作为一个简洁高效的博客平台,其添加浏览量的功能十分重要。以下是 Typecho 纯代码添加浏览量代码的步骤:1) 打开 Typecho 主题文件夹,找到 post.php 文件,打开并找到文章正文下方的 “<?php $this->content ();?>” 代码处。 2) 在该代码之前添加如下代码: <?php $db = Typecho_Db::get(); $cid = $this->cid; $sql = "UPDATE " . $db->getPrefix() . "contents SET views = (views + 1) WHERE cid = ".$cid; $db->query($sql); $views = $this->viewsNum($this->cid); ?> <p>阅读量:<?php echo $views;?></p>3) 保存文件,上传至服务器,刷新文章页面即可看到已经添加上去的浏览量功能。到这里纯代码添加浏览量代码就完成了
2023年05月13日
121 阅读
0 评论
0 点赞
2023-03-05
关于Typecho无法登陆后台解决方法
今天换了优刻得的cdn,登录恋爱清单后台的时候发现一直登录不上,还报错f12查看源代码的时候发现都是http请求在百度上看到对应的解决方案,编辑 Typecho 站点根目录下的文件 config.inc.php,在最后添加一行define('__TYPECHO_SECURE__',true); 问题是因为用户与浏览器之间是 HTTPS 交互,但实际上 PHP 接收到的是来自 Cloud Flare 的 HTTP 交互,所以 PHP 使用了 HTTP 进行响应,结合 Typecho 的一些特性形成了这个问题。小插曲腾云先锋(TDP,Tencent Cloud Developer Pioneer)是腾讯云 GTS 官方组建并运营的技术开发者群体。这里有最专业的开发者&客户,能与产品人员亲密接触,专有的问题&需求反馈渠道,有一群志同道合的兄弟姐妹。来加入属于我们开发者的社群吧 。
2023年03月05日
171 阅读
0 评论
2 点赞
1
2
3