Brains - 灵感乌托邦

『原创』『教程』Typecho后台撰写文章时插入标签(非插件)

前言

每次写文章的时候,都忘记填写标签,因为typecho的标签默认不在后台展示,配置了哪些标签也很容易忘记

然后就想着能不能在文章编辑时显示标签,方便写文章时能记得添上标签,所以就去找了几个教程

刚开始找到一个教程,可以在编辑时显示标签,需要用时直接复制粘贴到标签栏,但是也很麻烦

直到前几天逛博客时发现了一个插件,可以实现后台点击填入标签,打开插件发现功能实现方法很简单

所以就把插件的实现方法移植到了后台程序里,在此记录一下

效果展示

教程开始

其实很简单,直接把以下代码复制到 ./admin/write-post.php 指定位置就行了

{tabs}
{tabs-pane label="代码"}

{hide}

          <section class="typecho-post-option">
                <label for="token-input-tags" class="typecho-label"><?php _e('标签'); ?></label>
                <p>
                <input id="tags" name="tags" type="text" value="<?php $post->tags(',', false); ?>" class="w-100 text" />
                <style>.tagshelper a{cursor: pointer; padding: 0px 6px; margin: 2px 0;display: inline-block;border-radius: 2px;text-decoration: none;}.tagshelper a:hover{background: #ccc;color: #fff;}
                </style>
                <script> $(document).ready(function(){
                    $('#tags').after('<div style="margin-top: 35px;" class="tagshelper">标签选择:<ul style="list-style: none;border: 1px solid #D9D9D6;padding: 6px 12px; max-height: 240px;overflow: auto;background-color: #FFF;border-radius: 2px;"><?php
                        $stack = Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->stack;
                        $i = 0; 
                        while (isset($stack[$i])) {
                        echo "<a id=\"$i\" onclick=\"$(\'#tags\').tokenInput(\'add\', {id: \'".$stack[$i]['name']."\', tags: \'".$stack[$i]['name']."\'});\">",$stack[$i]['name'], "</a>";
                        $i++;
                        if (isset($stack[$i])) echo "  ";}
                        ?></ul></div>');
                    });
                </script>
                </p>
            </section>

{/hide}

{/tabs-pane}
{tabs-pane label="代码位置"}

{/tabs-pane}
{/tabs}

教程结束

就这么简单,快去试试吧!

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »