Typecho文章页面实现长久没有更新文章的提示
2023-01-09
分类: typecho
简介:方法打开主题目录下post.php文件,在适当位置添加如下代码,一般添加在post content后面(表示文章正文开始的地方) <div class="tip inlineBlock share" rel="nofollow"> <p> 本文最后更新于<?php echo date('Y年m月d日' , $this >modified);?>, 已超过<?php echo floor((time() ($this >modified))/86400);?>天没有更新。 如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢! </p> </div>注意:代码引用的css是handsome主题内置的,如果要用在其他主题,请自行把这个css扒下来!
typecho评论验证码插件
2022-12-24
分类: typecho
简介:很多用户受到垃圾评论的困扰,因为某些国内服务器无法连接到Akismet服务,所以垃圾评论肆虐。有的用户即使启用了Akismet插件,但成千上万条垃圾评论对服务器负载也造成了影响。因此我开发了一个验证码插件,有需要开发类似插件的用户也可以借鉴一下开发方法。使用方法很简单,下载插件解压后,将其上传至/usr/plugins/目录下,先在后台启用插件,然后编辑摸板,在评论的表单位置也就是comments的form标签之间的任何你认为合适的地方,加上如下代码<p><?php Captcha_Plugin::output(); ?></p>[hide]评论验证码插件.zip[/hide]
为Typecho主题集成文章目录功能(免插件实现文章目录功能)
2021-10-09
分类: typecho
简介:Typecho添加主题目录的教程好像不是很多,而且我找到的仅有的几个都是前台JS实现的,总感觉这样不如后台实现来的好。既然Typecho找不到现成的,只好“曲线救国”,由于实现文章目录的原理是通用的,所以就去WP里找了,那可是大把大把的。没多想,第一个就到WP果酱那里扒了他的插件的代码,因为我曾经也是水煮鱼大大的粉啊😭,他的几个作品我用的可以说是炉火纯青了。(自己写是不可能的,Ctrl+C+V 大法那么无敌😂)代码内容不过毕竟是WP下的东西,要移植到Typecho还是要改一改的,下面直接放出修改后的代码吧,使用方法继续往下看。function createCatalog($obj) { //为文章标题添加锚点 global $catalog; global $catalog_count; $catalog = array(); $catalog_count = 0; $obj = preg_replace_callback('/<h([1 6])(.*?)>(.*?)<\/h\1>/i', function($obj) { global $catalog; global $catalog_count; $catalog_count ++; $catalog[] = array('text' => trim(strip_tags($obj[3])), 'depth' => $obj[1], 'count' => $catalog_count); return '<h'.$obj[1].$obj[2].'><a name="cl '.$catalog_count.'"></a>'.$obj[3].'</h'.$obj[1].'>'; }, $obj); return $obj;
} function getCatalog() { //输出文章目录容器 global $catalog; $index = ''; if ($catalog) { $index = '<ul>'."\n"; $prev_depth = ''; $to_depth = 0; foreach($catalog as $catalog_item) { $catalog_depth = $catalog_item['depth']; if ($prev_depth) { if ($catalog_depth == $prev_depth) { $index .= '</li>'."\n"; } elseif ($catalog_depth > $prev_depth) { $to_depth++; $index .= '<ul>'."\n"; } else { $to_depth2 = ($to_depth > ($prev_depth $catalog_depth)) ? ($prev_depth $catalog_depth) : $to_depth; if ($to_depth2) { for ($i=0; $i<$to_depth2; $i++) { $index .= '</li>'."\n".'</ul>'."\n"; $to_depth ; } } $index .= '</li>'; } } $index .= '<li><a href="#cl '.$catalog_item['count'].'">'.$catalog_item['text'].'</a>'; $prev_depth = $catalog_item['depth']; } for ($i=0; $i<=$to_depth; $i++) { $index .= '</li>'."\n".'</ul>'."\n"; } $index = '<div id="toc container">'."\n".'<div id="toc">'."\n".'<strong>文章目录</strong>'."\n".$index.'</div>'."\n".'</div>'."\n"; } echo $index;
}
使用方法把上面的代码放到主题文件functions.php最后一行之前继续在functions.php内搜索关键词function themeInit如果有themeInit这个函数,则在themeInit这个函数内添加下面的代码if ($archive >is('single')) { $archive >content = createCatalog($archive >content);
}如果没有themeInit这个函数,则在functions.php最后一行之前添加下面的代码function themeInit($archive) { if ($archive >is('single')) { $archive >content = createCatalog($archive >content); }
}最后在需要输出文章目录的位置调用<?php getCatalog(); ?>即可这是通用的方法,具体到每个人使用时,可以根据自己的需求修改,不再赘述。