Code
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 | |
function subpage_peek() { | |
global $post; | |
$args = array( | |
'post_parent' => $post->ID, | |
'post_type' => 'page' | |
); | |
$subpages = new WP_query($args); | |
if ($subpages->have_posts()) : | |
$output = '<ul>'; | |
while ($subpages->have_posts()) : $subpages->the_post(); | |
$output .= '<li><strong><a href="'.get_permalink().'">'.get_the_title().'</a></strong> | |
<p>'.get_the_excerpt().'<br /> | |
<a href="'.get_permalink().'">続きを読む →</a></p></li>'; | |
endwhile; | |
$output .= '</ul>'; | |
else : | |
$output = '<p>ありません</p>'; | |
endif; | |
wp_reset_postdata(); | |
return $output; | |
} | |
add_shortcode('subpage_peek', 'subpage_peek'); | |
?> |
Screen shot
Note
Description | 固定ページで子ページを持つ親ページに使うショートコード。子ページを一覧表示させる。 出力されるマークアップは$outputの中身ですので変えたい場合はここを弄れば良いですね。 |
---|---|
WordPress Ver. | 3.3.1 |
Via | Display Excerpts of Child Pages with a Shortcode |