https://github.com/ashtaev/php-table-of-contents
A lightweight PHP library, for generating table of contents (TOC) in the style of Wikipedia.
https://github.com/ashtaev/php-table-of-contents
contents php table-of-contents toc
Last synced: 5 months ago
JSON representation
A lightweight PHP library, for generating table of contents (TOC) in the style of Wikipedia.
- Host: GitHub
- URL: https://github.com/ashtaev/php-table-of-contents
- Owner: ashtaev
- License: mit
- Created: 2019-03-15T13:06:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-21T07:13:43.000Z (about 7 years ago)
- Last Synced: 2025-11-13T09:29:28.713Z (7 months ago)
- Topics: contents, php, table-of-contents, toc
- Language: PHP
- Homepage:
- Size: 163 KB
- Stars: 5
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP Table of Contents
=============
[](https://packagist.org/packages/ashtaev/toc)
[](https://packagist.org/packages/ashtaev/toc)
[](https://packagist.org/packages/ashtaev/toc)
[](https://packagist.org/packages/ashtaev/toc)
A lightweight PHP library, for generating table of contents in the style of Wikipedia.
It automatically generates table of contents for your posts, pages and custom post types by parsing its contents for headers.
By doing so, you can let your readers jump to a corresponding header by clicking on a link in the TOC.
You can place this TOC anywhere in a post using the shortcodes.
You don’t have to add any links or create any anchors for this.
Built Wikipedia in mind, the table of contents by default appears before the first heading on a page.
You also get various methods to configure your TOC and control how it is going to appear.
Also, it sets no limit to the number of TOC you can create.
You can go on and have as many TOC as you want.
## Screenshots
They're rendered using the sample templates provided in the [templates](templates/) directory,
which depend on Bootstrap 4.
You can easily use your own custom HTML to render the table of contents instead.
Default template:

## Installation
Install with composer:
composer require ashtaev/toc
## Basic usage
Here's a quick example using the defaults:
Lorem ipsum
getPostWhithToc();
?>
This will output the following:
Lorem ipsum...
"1. Lorem ipsum
Lorem ipsum dolor...