Hackadelic TOC Boxes work in the sidebar as well. Out of the box. You can see a live demo on my blog by going to a post’s single view: The TOC box appears at the top of the left sidebar.1 This post here is a good example.
How I did it?
The trick is fairly simple: After enabling shortcode in widgets, I simply added a text widget with no title to my sidebar, and entered the shortcode:
[toc style="margin-bottom:1em; margin-right:1em"]
Since a TOC is only generated in “single mode” (meaning when viewing single posts or pages), the widget occupies no space on the front page or archive pages. In singular views, it expands to the TOC of the current post or page (if it has any headers).
Hence, this is an alternative way of “automatically” adding a TOC to all your posts – complementary to the auto-insertion feature. In particular in blogs that use in-post images extensively, adding a TOC in the sidebar is the less obtrusive and problematic way than auto-inserting it into the post, where it might interfere with the individual post layout / typesetting.
- How To Auto-Collapse TOC Boxes
- How To Couple a TOC Box to an Image
- Table Of Contents In The Sidebar
- Placing a TOC In The Sidebar Revisited - First Aid For Naughty Themes
- At least it’s at the top at time of this writing. I may move it in the future to another place, or remove it all together. [↩]