An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

PHP Table of Contents
=============

[![Latest Stable Version](https://poser.pugx.org/ashtaev/toc/v/stable)](https://packagist.org/packages/ashtaev/toc)
[![Total Downloads](https://poser.pugx.org/ashtaev/toc/downloads)](https://packagist.org/packages/ashtaev/toc)
[![Latest Unstable Version](https://poser.pugx.org/ashtaev/toc/v/unstable)](https://packagist.org/packages/ashtaev/toc)
[![License](https://poser.pugx.org/ashtaev/toc/license)](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...