代码 Typecho启用gzip优化加载速度 开启GZIP可以用来加快网站的打开速度 要如何开启GZIP压缩呢?找到网站根目录下的index.php文件,直接在<?php下面加入以下代码ob_start('ob_gzhandler');即可..
代码 创建一个跳转随机文章的独立页面 介绍创建一个随机阅读的独立页面演示https://typecho.team/random.html实现<?php /** * 随机阅读 * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; $db = Typecho_Db::get(); // 统计符合条件的文章总数 $countSql = $...
代码 Typecho获取页面加载时间 在主题functions.php中插入/** * 页面加载时间 */ function timer_start() { global $timestart; $mtime = explode( ' ', microtime() ); $timestart = $mtime[1] + $mtime[0]; return true; } timer_sta...
代码 Typecho显示在线状态 /*** * 在线状态 */ function get_last_login($user){ $user = '1'; $now = time(); $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $row = $db->fetchRow($db->se...
代码 Typecho 获取在线人数 在主题的functions.php中加入function onlinePeople() { // 使用 Helper 类获取主题路径 $theme_dir = Helper::options()->themeFile(Helper::options()->theme); $filename = $theme_dir . '/online.txt'; // ...
代码 Typecho 获取站点统计信息(带缓存) 在主题中最后插入// 获取站点统计信息(带缓存) function getSiteStatsWithCache() { // 使用文件缓存(兼容性最好) $cacheFile = __TYPECHO_ROOT_DIR__ . '/usr/cache/site_stats.cache'; $cacheTime = 3600; // 1小时缓存 if (file...