WordPress Plugin TOC+ with sub menus (Table Of Contents Plus)

WordPress Plugin: Add Sub-Menu Support for TOC+ (Table Of Contents Plus)

Are you coming from the TOC+ plugin Authors homepage ( http://dublue.com/plugins/toc/ ) and want to know how I did this?

This is a update request for TOC+ WordPress Plugin article.

 

This is an update request for the

TOC+ Plugin of WordPress, see https://wordpress.org/plugins/table-of-contents-plus/ and authors page here http://dublue.com/plugins/toc/

You now can use:

[sitemap_pages child_of="current"]

to show current sub-pages only. "current" will be replaced by the current pageID within the plugin function itself. See more on that the source code below.

Use:

[sitemap_pages child_of="1234"]

to show sub-pages of a given pageID.

 

How can I find a Page ID?

Easiest way to navigate to the page you want, then hoover over "Edit Page", then look at the URL you will find something like:

?post=1234?

(Yes, pages are "posts" internally...)

 

As you can see, I used it also in my footer a lot.

 

Support

PS: Like it? You can support me.

 

Source Code

File: toc.php updates

[php]
function shortcode_sitemap_pages( $atts )
{
global $post;

extract( shortcode_atts( array(
'heading' => $this->options['sitemap_heading_type'],
'label' => htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ),
'no_label' => false,
'exclude' => '',
'exclude_tree' => '',
'child_of' => $this->options['child_of']
), $atts )
);

$html='';
//$html.='<!-- child_of:   ' . $child_of . ' -->' . "\n";    // true

// -- [ sitemap_pages child_of="current" ]
if ( $child_of == "current" ) {
$child_of = $post->ID;
} else if ( is_numeric($child_of) ) {
// -- specific number
} else {
$child_of = 0;
}

$html.='<!-- child_of:   ' . $child_of . ' -->' . "\n";    // true
$html.='<!-- current ID: ' . $post->ID . ' -->' . "\n";  // 2311
$html.="\n";

/*
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) {
$html.='

<ul>' . $children . '</ul>

';
}
*/

if ( $heading < 1 || $heading > 6 )        // h1 to h6 are valid
$heading = $this->options['sitemap_heading_type'];

$html .= '

<div class="toc_sitemap">';

if ( !$no_label ) {
// label was set
$html .= '<h' . $heading . ' class="toc_sitemap_pages">' . $label . '</h' . $heading . '>';
}

$html .=
'

<ul class="toc_sitemap_pages_list">' .
wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree, 'child_of' => $child_of ) ) .
'</ul>

' .
'</div>

'
;

return $html;
}

[/php]

Happy hacking 😉

 

Helpful?

Schreiben Sie einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Warenkorb
Scroll to Top