Skip to content

Instantly share code, notes, and snippets.

@tobedoit
Created November 26, 2012 03:48
Show Gist options
  • Save tobedoit/4146524 to your computer and use it in GitHub Desktop.
Save tobedoit/4146524 to your computer and use it in GitHub Desktop.
Wordpress: child page shortcode
/* Child Page with Shorcode ***********************************************************************************
** http://wp.tutsplus.com/tutorials/quick-tip-display-excerpts-of-child-pages-with-a-shortcode/ ***************
** http://botcrawl.com/how-to-change-or-remove-the-howdy-greeting-message-on-the-wordpress-user-menu-bar/ ** */
/* !차일드 페이지 코드 ***************************************************************************************** */
function subpage_peek() {
global $post;
//query subpages
$args = array(
'post_parent' => $post->ID,
'order' => 'ASC',
'post_type' => 'page'
);
$subpages = new WP_query($args);
// create output
if ($subpages->have_posts()) :
$output = '​<div class="et-custom-list etlist-check"><ul>';
while ($subpages->have_posts()) : $subpages->the_post();
$output .= '<li><h2 style="font-size: 18px; padding-top: 5px;" class="title"><a href="'.get_permalink().'">'.get_the_title().'</a></h1>
<p class="space-bottom">'.get_the_excerpt().'<br />
<a href="'.get_permalink().'">더 보기 →</a></p></li>';
endwhile;
$output .= '</ul></div>';
else :
$output = '<p>No subpages found.</p>';
endif;
// reset the query
wp_reset_postdata();
// return something
return $output;
}
add_shortcode('subpage_peek', 'subpage_peek');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment