Wp Back To Toc

post_id: 62 / post_date: 2011-07-09



[tab: PS]

I found a nice plugin for adding a table of contents to a post (like the wiki pages have)

However it had one limitation, there is no back to top link. Since we want to go back to the toc (which can be at the top / bottom), Ive called it the back_to_toc feature.

It has 3 options - not to show / show text / show image.

See snippets overleaf or explore the  code (line 559 of toc.php is where the real changes start). Or view it in action.

[tab: code]

The plugin filters the the_content method and the code added to it is

toc.php

//Line 560
$btt = "";
if ($this->options['back_to_toc'] != TOC_BACKTOTOC_NONE)
{
	$img = $this->options['back_to_toc'] == TOC_BACKTOTOC_IMG;
	$bttText = $img ? " " : "top"; //space else image doesnt show
	$bttSuffix = $img ? "_img" : "";
	$btt = '' . $bttText . '';
}

//Line 617
if ($this->options['back_to_toc'] != TOC_BACKTOTOC_NONE)
	$html = '' . $html;

screen.css

a.toc_to_top { float: right; color: #444; } a.toc_to_top:hover { color: #C04242; }
a.toc_to_top_img { float: right; background: url(back_to_top.png) no-repeat left center; width: 40px; }
a.toc_to_top, a.toc_to_top_img { text-decoration: none; }

[tab: ss]