kunoichi / toc-generator
从 h1-h6 标签生成目录。
1.0.2
2023-08-22 06:00 UTC
Requires
- php: >=7.0
- ext-dom: *
- masterminds/html5: ^2.7
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-22 08:34:24 UTC
README
从 h1-h6 标签生成目录。
安装
运行 composer。
comopser require kunoichi/toc-generator
并包含自动加载器。
require __DIR__ . '/vendor/autoload.php';
使用方法
PHP
W.I.P
WordPress
在你的 functions.php
// Register TOC. // If you have theme option for it, // detect conditions. add_action( 'init', function() { $parser = new Kunoichi\TocGenerator\WpParser(); $parser->set_title( __( 'Table of Contents', 'your-theme' ) ); } );
并在你想要的地方渲染 TOC(例如,在你的 singular.php
)。你需要 $post_id
来渲染 TOC。在这个例子中,使用了 get_queried_object_id()
。
Kunoichi\TocGenerator\WpParser::render( get_queried_object_id() );