侧边栏壁纸
    • 累计撰写 204 篇文章
    • 累计收到 554 条评论
    Typecho后台加增加自动添加tag标签功能
    2022-11-19  195 阅读 0 评论 1 点赞

    Typecho后台加增加自动添加tag标签功能

    奉天
    2022-11-19 / 0 评论 / 195 阅读 / 检测收录中......
    温馨提示:
    本文最后更新于2022年11月19日,已超过495天没有更新,若内容或图片失效,请留言反馈。

    给typecho加上主题自动添加tag标签功能。
    教程

    在自己的主题上的 functions.php 里面添加一句

    Typecho_Plugin::factory('admin/write-post.php')->bottom = array('tagshelper', 'tagslist');

    然后继续添加到functions.php

    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!['+file+'](' + url + ')\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
        }
    }

    结束了,赶紧写文章去吧!!!

    1

    海报

    正在生成.....

    评论 (0)

    取消