Jun 282006

::iimageright(“ylsy_toc.jpg”,”Table of Contents”)::

Scott at Fucoder.com has updated his Table of Contents Generator plugin for WordPress. The plugin scans through your post and builds a “Table of Contents” from the HTML headings (h1,h2,…) within the post. It also creates an anchor link for each heading so your readers can jump right to that section from the TOC.

You can place the TOC in your posts in one of two ways. You can place inside individual posts that you want to have the TOC or you can place some php code in the template and then the TOC will be placed in each post that uses that template.

We use WordPress for our office Content Management System and the posts in 2 categories should always have a TOC. I am going to set up special templates for those 2 categories using the php code so I do not have to manually add to each post in those categories.

I also use [Markdown plugin->] which does not play well with this plugin but another user already has figured out a hack by changing one line of the plugin from:

add_filter(‘the_posts’, array(new YLSY_TableOfContents, ‘the_posts’));


add_filter(‘the_content’, array(new YLSY_TableOfContents, ‘the_content’));

Finally, the TOC is all coded and ready for some css magic that you can modify to work as you see fit.

  One Response to “Table of Contents Generator plugin for WordPress”

  1. Scott Yang posted this comment on his blog regarding the ‘fix’ to make this plugin and Markdown play nice together:

    The reason why TOC plugin does not use ?the_content? for filtering is because ?the_content? will only be able to get a sub-section of the content, especially in the situation where you have or . ?the_content? will only give you the section to be rendered, so that might mean one specific page or the teaser, whereas TOC is especially useful in multi-page long articles, where it can generate TOC for all pages.

    So, be warned :)

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>