diff --git a/extended-toc.php b/extended-toc.php
index 80cbb29..5db1fa5 100644
--- a/extended-toc.php
+++ b/extended-toc.php
@@ -3,7 +3,7 @@
Plugin Name: Extended Table of Contents (with nextpage support)
Plugin URI: http://www.happybooking.de/wordpress/plugins/extended-toc
Description: This plugin automatically generates and inserts a table of contents (ToC) to your pages and posts, based on tags h1-h6. Whenever the plugin discovers more than a certain amount of headings (default: 3) the ToC is inserted at the top of the page. This plugin also can handle posts that are divided into pages by the nextpage-wordpress-tag. Any feedback or suggestions are welcome.
-Version: 0.6.4
+Version: 0.7.0
Author: HappyBooking UG // Daniel Boldura
Author URI: http://www.happybooking.de/
@@ -34,9 +34,11 @@ Author URI: http://www.happybooking.de/
* 4. Config the ToC within a markup e.g. [extoc start=5 headers=1,2,3 title="My table of contents"] oder [extoc start=5 headers=1,2,3 notitle]
*/
-define( 'EXTENDED_TOC_VERSION', '0.6.4' );
+define( 'EXTENDED_TOC_VERSION', '0.7.0' );
define( 'EXTENDED_TOC_ID', 'extended_toc' );
define( 'EXTENDED_TOC_NAME', 'Extended-ToC' );
+define( 'TOC_MIN_START', 2 );
+define( 'TOC_MAX_START', 10 );
if( !class_exists('ExToC') ) {
class ExToC
@@ -46,7 +48,7 @@ if( !class_exists('ExToC') ) {
private $fullcontent = "";
private $pages = array();
private $ID = 0;
- private $counter = 1;
+ private $counter = array();
private $totalHeadings = 0;
public function __construct() {
@@ -60,6 +62,7 @@ if( !class_exists('ExToC') ) {
'show_heading_text' => true,
'auto_insert_post_types' => array('page', 'post'),
'heading_levels' => array('1', '2', '3', '4', '5', '6'),
+ 'show_hierarchy' => true,
);
$options = get_option( EXTENDED_TOC_ID, $defaults );
$this->options = wp_parse_args( $options, $defaults );
@@ -107,6 +110,9 @@ if( !class_exists('ExToC') ) {
array(
'heading_text' => stripslashes( trim($_POST['heading_text']) ),
'auto_insert_post_types' => @(array)$_POST['auto_insert_post_types'],
+ 'start' => intval($_POST['start']),
+ 'show_heading_text' => (isset($_POST['show_heading_text']) && $_POST['show_heading_text']) ? true : false,
+ 'show_hierarchy' => (isset($_POST['show_hierarchy']) && $_POST['show_hierarchy']) ? true : false,
)
);
@@ -139,6 +145,13 @@ if( !class_exists('ExToC') ) {
@@ -195,13 +231,16 @@ if( !class_exists('ExToC') ) {
$toc_content .= "";
$toc_content .= $this->extract_toc();
$toc_content .= "
";
-
+
if( $this->totalHeadings >= $this->options['start'] )
return $toc_content . $this->content;
else
return $this->content;
}
+ private function check_for_first_toc_position() {
+ }
+
/** Extract the full unshortened content from the post **/
private function extract_full_post_content() {
global $post;
@@ -233,7 +272,7 @@ if( !class_exists('ExToC') ) {
preg_match_all('/(]*>).*<\/h\2>/msuU', $this->pages[$pagenum-1], $matches, PREG_SET_ORDER);
/** Check the headings that are desired */
- if ( count($this->options['heading_levels']) != 6 ) {
+ if( count($this->options['heading_levels']) != 6 ) {
$new_matches = array();
for ($i = 0; $i < count($matches); $i++) {
if ( in_array($matches[$i][2], $this->options['heading_levels']) )
@@ -244,6 +283,10 @@ if( !class_exists('ExToC') ) {
$items = "";
+ /** Take first h-level as baseline */
+ $minLevel = $matches[0][2]; // lowest level e.g. h3
+ $currentLevel = $minLevel;
+
for( $i = 0; $i < count($matches); $i++ ) {
/** get anchor and add to find and replace arrays **/
$anchor = $this->url_encode_anchor($matches[$i][0]);
@@ -258,12 +301,33 @@ if( !class_exists('ExToC') ) {
''
),
$this->content
- );
-
+ );
+
+ /** Check if header lower current header, then add level and update current header */
+ if( $matches[$i][2] > $currentLevel && $this->options['show_hierarchy'] == true) {
+ $currentLevel = $matches[$i][2];
+ $this->counter[$currentLevel] = 1;
+ }
+ else if( $matches[$i][2] < $currentLevel && $matches[$i][2] >= $minLevel && $this->options['show_hierarchy'] == true) {
+ $currentLevel = $matches[$i][2];
+ $this->counter[$currentLevel] += 1;
+ }
+ else
+ $this->counter[$currentLevel] += 1;
+
/** build html */
- $items .= '';
+ $items .= '';
diff --git a/readme.txt b/readme.txt
index ca59b01..6108e25 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Donate link: http://www.happybooking.de/wordpress/plugins/extended-toc/donate
Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
Requires at least: 3.0.1
Tested up to: 3.5.2
-Stable tag: 0.6.4
+Stable tag: 0.7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -39,6 +39,10 @@ If you have any questions or suggestions please contact us at any time: support@
== Changelog ==
+= 0.7.0 =
+* Show the header hierarchy within the ToC
+* Further options for (min amount of headers, show/don't show header, show headers hierarchy)
+
= 0.6.4 =
* Released: 1 July 2013
* First release of the ToC supporting nextpage-tag
diff --git a/style.css b/style.css
index 7514614..200c40d 100644
--- a/style.css
+++ b/style.css
@@ -1,4 +1,4 @@
-#toc-np-container {
+#toc-np-container {
background: #f9f9f9;
border: 1px solid #aaa;
padding: 1em;
@@ -12,6 +12,26 @@
padding: 0
}
+#toc-np-container li.header-level-2 {
+ padding-left: 15px;
+}
+
+#toc-np-container li.header-level-3 {
+ padding-left: 30px;
+}
+
+#toc-np-container li.header-level-4 {
+ padding-left: 45px;
+}
+
+#toc-np-container li.header-level-5 {
+ padding-left: 60px;
+}
+
+#toc-np-container li.header-level-6 {
+ padding-left: 75px;
+}
+
#toc-np-container ul {
margin-top: 1em;
}
@@ -24,6 +44,11 @@
text-decoration: underline;
}
+#toc-np-container .toc-np-number {
+ display: inline-block;
+ padding-right: 15px;
+}
+
#toc-np-container #toc-np-title {
font-weight: bold;
margin: 0;