给typecho加上主题自动添加tag标签功能
当然也有这样的插件,安装启用就简单多了
插件下载地址:https://qqdie.com/archives/tyepcho-tag-select-plugin.html
功能如图所示:
如果不需要插件,也可以在自己的主题上整合添加,首先在functions.php里面添加一句
- Typecho_Plugin::factory('admin/write-post.php')->bottom = array('tagshelper', 'tagslist');
在编辑文章的时候,触发tagslist事情函数
然后继续添加
- class tagshelper {
- public static function tagslist()
- {
- $tag="";$taglist="";$i=0;//循环一次利用到两个位置
- Typecho_Widget::widget('Widget_Metas_Tag_Cloud', 'sort=count&desc=1&limit=200')->to($tags);
- while ($tags->next()) {
- $tag=$tag."'".$tags->name."',";
- $taglist=$taglist."<a id=".$i." onclick=\"$(\'#tags\').tokenInput(\'add\', {id: \'".$tags->name."\', tags: \'".$tags->name."\'});\">".$tags->name."</a>";
- $i++;
- }
- ?><style>.Posthelper a{cursor: pointer; padding: 0px 6px; margin: 2px 0;display: inline-block;border-radius: 2px;text-decoration: none;}
- .Posthelper a:hover{background: #ccc;color: #fff;}.fullscreen #tab-files{right: 0;}/*解决全屏状态下鼠标放到附件上传按钮上导致的窗口抖动问题*/
- </style>
- <script>
- function chaall () {
- var html='';
- $("#file-list li .insert").each(function(){
- var t = $(this), p = t.parents('li');
- var file=t.text();
- var url= p.data('url');
- var isImage= p.data('image');
- if ($("input[name='markdown']").val()==1) {
- html = isImage ? html+'\n\n':''+html+'';
- }else{
- html = isImage ? html+'<img src="' + url + '" alt="' + file + '" />\n':''+html+'';
- }
- });
- var textarea = $('#text');
- textarea.replaceSelection(html);return false;
- }
-
- function chaquan () {
- var html='';
- $("#file-list li .insert").each(function(){
- var t = $(this), p = t.parents('li');
- var file=t.text();
- var url= p.data('url');
- var isImage= p.data('image');
- if ($("input[name='markdown']").val()==1) {
- html = isImage ? html+'':html+'\n['+file+'](' + url + ')\n';
- }else{
- html = isImage ? html+'':html+'<a href="' + url + '"/>' + file + '</a>\n';
- }
- });
- var textarea = $('#text');
- textarea.replaceSelection(html);return false;
- }
- function filter_method(text, badword){
- //获取文本输入框中的内容
- var value = text;
- var res = '';
- //遍历敏感词数组
- for(var i=0; i<badword.length; i++){
- var reg = new RegExp(badword[i],"g");
- //判断内容中是否包括敏感词
- if (value.indexOf(badword[i]) > -1) {
- $('#tags').tokenInput('add', {id: badword[i], tags: badword[i]});
- }
- }
- return;
- }
- var badwords = [<?php echo $tag; ?>];
- function chatag(){
- var textarea=$('#text').val();
- filter_method(textarea, badwords);
- }
- $(document).ready(function(){
- $('#file-list').after('<div class="Posthelper"><a class="w-100" onclick=\"chaall()\" style="background: #467B96;background-color: #3c6a81;text-align: center; padding: 5px 0; color: #fbfbfb; box-shadow: 0 1px 5px #ddd;">插入所有图片</a><a class="w-100" onclick=\"chaquan()\" style="background: #467B96;background-color: #3c6a81;text-align: center; padding: 5px 0; color: #fbfbfb; box-shadow: 0 1px 5px #ddd;">插入所有非图片附件</a></div>');
- $('#tags').after('<div style="margin-top: 35px;" class="Posthelper"><ul style="list-style: none;border: 1px solid #D9D9D6;padding: 6px 12px; max-height: 240px;overflow: auto;background-color: #FFF;border-radius: 2px;margin-bottom: 0;"><?php echo $taglist; ?></ul><a class="w-100" onclick=\"chatag()\" style="background: #467B96;background-color: #3c6a81;text-align: center; padding: 5px 0; color: #fbfbfb; box-shadow: 0 1px 5px #ddd;">检测内容插入标签</a></div>');
- });
- </script>
- <?php
- }
- }
记得插件是有个自动添加的功能,但是我去掉了,标签这种东西还是灵活地自行配置比较好吧……
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/1046
1 条评论
3.4k
发表评论
热门文章
自媒体博客Spimes主题45w 阅读
Spimes主题专为博客、自媒体、资讯类的网站设计....
Splity博客双栏主题15w 阅读
仿制主题,Typecho博客主题,昼夜双版设计,可....
vCard主题个人简历主题13w 阅读
一款个人简历主题,可以简单搭建一下,具体也比较简单....
Spzac个人资讯下载类主题12w 阅读
用于作品展示、资源下载,行业垂直性网站、个人博客,....
热评文章
自媒体博客Spimes主题424 评论
Splity博客双栏主题191 评论
Spzac个人资讯下载类主题89 评论
Splinx博客图片主题35 评论
Spzhi知识付费社区主题34 评论
三栏清新博客S_blog主题31 评论
vCard主题个人简历主题29 评论
Pure轻简主题29 评论
chenyu
4月7日
能不能支持deepseek