Typecho配置 插件,自定义修改。尽量简单

MenuTree 自动生成文章目录树

搬运github

使用方法

在文章某处地方加上<!-- index-menu --删除文字>,程序会把这个注释替换成目录树

样式

.index-menu         
.index-menu-list    列表 ul
.index-menu-item    每个目录项 li
.index-menu-link    目录项连接 a
.menu-target-fix{display: block;position: relative;top: -60px; //偏移量}    锚点定位偏移

自定义编辑器功能(一键插入 MenuTree 生成目录)

安装 menu tree 插件,自定义编辑器按钮 toc(看自己喜好) 用于插入 字符串

// .../admin/editor-js.php
// 添加按钮汉化
options.strings = {
  ...
      toc: '<?php _e('TOC'); ?> \x3c!-- index-menu --\x3e',
// .../admin/js/pagedown-js

...
// search `more`,在之后添加 toc 相关功能
// 添加默认英文介绍
more:"More contents \x3c!--more--\x3e Ctrl+M",
toc:"TOC contents \x3c!-- index-menu --\x3e",


// ...
// 显示并将点击事件绑定方法 doTOC
f.more=t("wmd-more-button",d("more"),"-280px",h("doMore")),n(3),
f.toc=t("wmd-more-button",d("toc"),"-280px",h("doToc")),n(3),

// ...
// search `doMore`,在之后添加 doToc 相关方法

e.doMore=function(e,t){e.startTag="\x3c!--more--\x3e\n\n",e.selection="",e.skipLines(2,0,!0)},
e.doToc=function(e,t){e.startTag="\x3c!-- index-menu --\x3e\n\n",e.selection="",e.skipLines(2,0,!0)},

统计访问人数

最下方添加统计访问人数的功能,数据可能不是很准确,聊胜于无

参考地址

代码高亮

控制台 》 外观 》 主题设置 》 head.php

<head>
...
    <!-- prism.js 高亮代码 主题 和支持的语法 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism-themes/1.9.0/prism-one-light.min.css" integrity="sha512-hS/3ZdmvOJPB/KZXZF9mUeMQuoNmo6BSiJHdUajzlhIs0CTBZMmJbtBkxMJAx7nm7IvigDv8N925UeuM0M96gg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" integrity="sha512-7Z9J3l1+EYfeaPKcGXu3MS/7T+w19WtKQY/n+xzmw4hZhJ9tyYmcUS+4QqAlzhicE5LAfMQSF3iFTK9bQdTxXg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

</head>

其他的主题
添加支持语言

添加最热文章

//...usr/theme/function.php

/*
* 最热文章
*/
function get_most_view_post()
{
    $db = Typecho_Db::get();
    // 执行 SQL 查询,获取 views 列最大的前 7 行数据
    $result = $db->query($db->select()->from('table.contents')->where('type = ?', 'post')->order('views','desc')->limit(7));
    // 获取并转换成数组
    if ($result) {
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        return $rows;
    } else {
        echo "查询失败:";
    }

}
//...usr/theme/sidebar.php
    <?php if (!empty($this->options->sidebarBlock) && in_array('ShowRecentPosts', $this->options->sidebarBlock)): ?>
        <section class="widget">
            <h3 class="widget-title"><?php _e('最热文章'); ?></h3>
            <ul class="widget-list">
                <?php $rows = get_most_view_post();
                $length = count($rows);
                for ($i = 0; $i < $length; $i++) {
                    echo "<li><a href=\"/index.php/archives/" . $rows[$i]['slug'] . "\">" . $rows[$i]['title'] . "</a></li>";
                }
                ?>
            </ul>
        </section>
    <?php endif; ?>

标签: typecho Views: 454