Created
February 18, 2014 18:16
-
-
Save wpmark/9076534 to your computer and use it in GitHub Desktop.
A simple WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: wpamrk Page Children Shortcode | |
Plugin URI: http://markwilkinson.me | |
Description: A shortcode that outputs the current pages children either with or without their featured image. | |
Version: 0.1 | |
Author: Mark Wilkinson | |
Author URI: http://http://markwilkinson.me/ | |
*/ | |
/*************************************************************** | |
* Function wpmark_shortcode_list_chidren() | |
* Shortcode function to list the current pages children | |
***************************************************************/ | |
function wpmark_shortcode_list_chidren( $atts ) { | |
/* extract the shortcode args, making each available as $variable */ | |
extract( shortcode_atts( | |
array( | |
'images' => 'false', | |
), | |
$atts ) | |
); | |
global $post; | |
/* set query args */ | |
$wpmark_children_args = array( | |
'post_type' => 'page', | |
'posts_per_page' => -1, | |
'post_parent' => $post->ID, | |
); | |
/* build the new query */ | |
$wpmark_children = new WP_Query( $wpmark_children_args ); | |
/* check we have children */ | |
if( $wpmark_children->have_posts() ) { | |
/* check whether we are including the featured image */ | |
if( $images == 'false' ) { | |
$html = '<ul class="list-children">'; | |
} | |
/* loop through posts */ | |
while( $wpmark_children->have_posts() ) : $wpmark_children->the_post(); | |
/* check whether we are including the featured image */ | |
if( $images == 'true' ) { | |
$html .= '<div id="childpage-' . get_the_ID(). '" class="list-children-page list-children-page-' . get_the_ID() . '"><h2 class="child-title">' . get_the_title() . '</h2>'; | |
$html .= '<div class="child-image">' . get_the_post_thumbnail( $post->ID, 'large' ) . '</div>'; | |
$html .= '<div class="child-content">' . wpautop( get_the_excerpt() ) . '<p class="child-link"><a href="' . get_permalink() . '">Read more »</a></p></div><div style="clearfix"></div>'; | |
$html .= '</div>'; | |
/* not including featured images */ | |
} else { | |
$html .= '<li id="childpage-' . get_the_ID(). '" class="list-children-page list-children-page-' . get_the_ID() . '"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; | |
} | |
/* end loop */ | |
endwhile; | |
/* check whether we are including the featured image */ | |
if( $images == 'false' ) { | |
$html .= '</ul>'; | |
} | |
} | |
/* reset the query */ | |
wp_reset_query(); | |
return $html; | |
} | |
add_shortcode( 'wpmark_list_children', 'wpmark_shortcode_list_chidren' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment