Skip to content

Instantly share code, notes, and snippets.

@aliharis
Created December 16, 2014 04:26
Show Gist options
  • Save aliharis/5df2defc6cdb92bfd705 to your computer and use it in GitHub Desktop.
Save aliharis/5df2defc6cdb92bfd705 to your computer and use it in GitHub Desktop.
WP Shortcode: [listpages]
<?php
/**
* Shortcode: [listpages]
* @return title of current page followed by child pages
*/
function listpages_func() {
global $post;
$html = '';
if ($post->post_parent)
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&sort_column=menu_order');
else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&sort_column=menu_order');
if ($children):
$html .= '<h4 style="margin-bottom:5px; padding-bottom:3px;">';
$html .= '<a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>';
$html .= '</h4>';
$html .= '<ul class="sc_list sc_list_style_arrows subpages">';
$html .= $children;
$html .= '</ul>';
endif;
return $html;
}
add_shortcode('listpages', 'listpages_func');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment