diff --git a/extended-toc.php b/extended-toc.php index 02a3ad5..f52c360 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. By using the markups [extoc] you can decide where to insert the ToC. Also you can use a whitelist by disable general ToC insertion and insert the ToC to special pages/subpages/posts by [extoc]. Otherwise you can use a blacklist and disable the ToC only on special pages/subpages/posts by using the [noextoc] markup. Any feedback or suggestions are welcome. -Version: 0.8.0 +Version: 0.8.1 Author: HappyBooking UG // Daniel Boldura Author URI: http://www.happybooking.de/ @@ -34,7 +34,7 @@ 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.8.0' ); +define( 'EXTENDED_TOC_VERSION', '0.8.1' ); define( 'EXTENDED_TOC_ID', 'extended_toc' ); define( 'EXTENDED_TOC_NAME', 'Extended-ToC' ); define( 'TOC_MIN_START', 2 ); @@ -63,6 +63,7 @@ if( !class_exists('ExToC') ) { 'auto_insert_post_types' => array('page', 'post'), 'heading_levels' => array('1', '2', '3', '4', '5', '6'), 'show_hierarchy' => true, + 'number_list_items' => true, ); $options = get_option( EXTENDED_TOC_ID, $defaults ); $this->options = wp_parse_args( $options, $defaults ); @@ -113,6 +114,7 @@ if( !class_exists('ExToC') ) { '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, + 'number_list_items' => (isset($_POST['number_list_items']) && $_POST['number_list_items']) ? true : false, ) ); @@ -191,6 +193,13 @@ if( !class_exists('ExToC') ) { options['show_hierarchy'] ) echo ' checked="checked"'; ?> /> + + + + + options['number_list_items'] ) echo ' checked="checked"'; ?> /> + + @@ -266,10 +275,7 @@ if( !class_exists('ExToC') ) { // Absolute backup, return the content. This point should actually never be reached return $content; } - - private function check_for_first_toc_position() { - } - + /** Extract the full unshortened content from the post **/ private function extract_full_post_content() { global $post; @@ -309,6 +315,8 @@ if( !class_exists('ExToC') ) { } $matches = $new_matches; } + + // echo "
"; print_r($matches); echo "
"; $items = ""; @@ -319,8 +327,8 @@ if( !class_exists('ExToC') ) { for( $i = 0; $i < count($matches); $i++ ) { /** get anchor and add to find and replace arrays **/ $anchor = $this->url_encode_anchor($matches[$i][0]); - $find[] = $matches[$i][0]; - $this->content = str_replace( + $find = $matches[$i][0]; + $replace = str_replace( array( $matches[$i][1], // start of heading '' // end of heading @@ -329,8 +337,10 @@ if( !class_exists('ExToC') ) { $matches[$i][1] . '', '' ), - $this->content - ); + $matches[$i][0] + ); + + $this->content = str_replace($find, $replace, $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) { @@ -347,16 +357,21 @@ if( !class_exists('ExToC') ) { /** build html */ $items .= '
  • '; $items .= ''; - $items .= ""; - if( $this->options['show_hierarchy'] == true ) { - for( $j = $minLevel; $j < $currentLevel; $j++ ) { - $items = $items . $this->counter[$j] . "."; + // Show numbers only if user wants it + if( $this->options['number_list_items'] ) { + $items .= ""; + + if( $this->options['show_hierarchy'] == true ) { + for( $j = $minLevel; $j < $currentLevel; $j++ ) { + $items = $items . $this->counter[$j] . "."; + } } + $items = $items . $this->counter[$currentLevel]; + + $items .= ""; } - $items = $items . $this->counter[$currentLevel]; - $items .= ""; $items .= strip_tags($matches[$i][0]) . ''; $items .= '
  • '; diff --git a/readme.txt b/readme.txt index d54ace7..8dec0db 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.7.0 +Stable tag: 0.8.1 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.8.1 = +* Switch on/off the numbering of the list items (headers) +* Anchor bugs fixed + = 0.8.0 = * Override the ToC position by using the markup [extoc] * Insert the ToC only in special pages/subpages/posts by using the markup [extoc]