固定ページで子ページのリンクやタイトル、抜粋を一覧表示させるショートコード

Ads

Code

<?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');
?>
view raw gistfile1.aw hosted with ❤ by GitHub

Screen shot

Note

Description 固定ページで子ページを持つ親ページに使うショートコード。子ページを一覧表示させる。
出力されるマークアップは$outputの中身ですので変えたい場合はここを弄れば良いですね。
WordPress Ver. 3.3.1
Via Display Excerpts of Child Pages with a Shortcode