WordPress.org

Ready to get started?Download WordPress

Forums

List Pages Shortcode
Add Support for Custom Post Types? (1 post)

  1. Mike Schinkel
    Member
    Posted 3 years ago #

    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):

    <?php
    /*
    Plugin Name: List Pages Shortcode
    Plugin URI: http://www.aaronharp.com/dev/list-pages-shortcode/
    Description: Introduces the [list-pages] and [child-pages] <a href="http://codex.wordpress.org/Shortcode_API">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="http://codex.wordpress.org/Template_Tags/wp_list_pages">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: http://www.aaronharp.com
    */ 
    
    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);
    	if(!empty($out))
    		$out = '<ul class="'.$atts['class'].'">' . $out . '</ul>';
    
      return $out;
    }
    
    add_shortcode('child-pages', 'shortcode_list_pages');
    add_shortcode('list-pages', 'shortcode_list_pages');
    
    ?>

    http://wordpress.org/extend/plugins/list-pages-shortcode/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic