Support » Plugin: List Pages Shortcode » [Plugin: List Pages Shortcode] Add Support for Custom Post Types?

  • Can I suggest you add support for Custom Post Types? It will only take one line of code; here is your plugin in its entirety modified to support Custom Post Types (the code I added is the first line of the array in the assigned of the $defaults variable):

    Plugin Name: List Pages Shortcode
    Plugin URI:
    Description: Introduces the [list-pages] and [child-pages] <a href="">shortcodes</a> for easily displaying a list of pages within a post or page.  Both shortcodes accept all parameters that you can pass to the <a href="">wp_list_pages()</a> function.  For example, to show a page's child pages sorted by title simply add [child-pages sort_column="post_title"] in the page's content.
    Author: Aaron Harp
    Version: 1.0
    Author URI:
    function shortcode_list_pages($atts, $content, $tag) {
    	global $post;
    	// set defaults
    	$defaults = array(
    	    'post_type'   => 'page',
    	    'class'       => $tag,
    	    'depth'       => 0,
    	    'show_date'   => '',
    	    'date_format' => get_option('date_format'),
    	    'exclude'     => '',
    	    'child_of'    => 0,
    	    'title_li'    => '',
    	    'authors'     => '',
    	    'sort_column' => 'menu_order, post_title',
    	    'link_before' => '',
    	    'link_after'  => '',
    	    'exclude_tree'=> '',
    	// merge user provided atts with defaults
    	$atts = shortcode_atts($defaults, $atts);
    	// set necessary params
    	$atts['echo'] = 0;
    	if($tag == 'child-pages')
    		$atts['child_of'] = $post->ID;	
    	// create output
    	$out = wp_list_pages($atts);
    		$out = '<ul class="'.$atts['class'].'">' . $out . '</ul>';
      return $out;
    add_shortcode('child-pages', 'shortcode_list_pages');
    add_shortcode('list-pages', 'shortcode_list_pages');

  • The topic ‘[Plugin: List Pages Shortcode] Add Support for Custom Post Types?’ is closed to new replies.