From e65c9a540a0490f1a23f574e382aa6dc68cead7e Mon Sep 17 00:00:00 2001 From: Christoph Tornau Date: Fri, 27 Oct 2017 22:04:22 +0200 Subject: [PATCH 1/2] The following two features were added to the [sitemap_pages]-shortcode: - only_subpages (default is false) If true, only subpages of the current page appear in the list - sort_column (default is menu_order) Defines how the entries are sorted. wp_list_pages() got a list of possible arguments: Comma-separated list of column names to sort the pages by. Accepts 'post_author', 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. I think menu_order is the best of these. Before the posts where just sorted like they were placed in the database. Now the WordPress menuorder is taken into account. --- trunk/toc.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/trunk/toc.php b/trunk/toc.php index d98c810..44ab27f 100644 --- a/trunk/toc.php +++ b/trunk/toc.php @@ -346,18 +346,30 @@ function shortcode_sitemap_pages( $atts ) 'label' => htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ), 'no_label' => false, 'exclude' => '', - 'exclude_tree' => '' + 'exclude_tree' => '', + 'only_subpages' => false, + 'sort_column' => 'menu_order' // By default we sort the entries by the given menu order within WP ), $atts ) ); if ( $heading < 1 || $heading > 6 ) // h1 to h6 are valid $heading = $this->options['sitemap_heading_type']; + + // 0 is the default-value for the child_of attribute of wp_list_pages() + $only_subpages_of = 0; + + // If only subpages should be listed, we get the ID of the page here + if ($only_subpages) { + global $post; + $only_subpages_of = $post->ID; + } $html = '
'; if ( !$no_label ) $html .= '' . $label . ''; $html .= '' . '
' ; From 5234fc68b830a5a3dbd06fa4ff0ad681b7182a7e Mon Sep 17 00:00:00 2001 From: Christoph Tornau Date: Fri, 10 Nov 2017 15:00:21 +0100 Subject: [PATCH 2/2] Bugfix if only_subpages is missing --- trunk/toc.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trunk/toc.php b/trunk/toc.php index 44ab27f..2eaf311 100644 --- a/trunk/toc.php +++ b/trunk/toc.php @@ -367,10 +367,13 @@ function shortcode_sitemap_pages( $atts ) $html = '
'; if ( !$no_label ) $html .= '' . $label . ''; $html .= - '
    ' . - wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree, - 'child_of' => $only_subpages_of, 'sort_column' => $sort_column ) ) . - '
' . + '
    ' . + $only_subpages ? + wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree, + 'child_of' => $only_subpages_of, 'sort_column' => $sort_column ) ) : + wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree, + 'sort_column' => $sort_column ) ). + '
'. '
' ;