親ページもリストに含む形にしたかったので、このようになりました。
今、表示中のページ(サブページ)の親ページに属するページ一覧で、
サブページが存在しなかったり、ページ以外のコンテンツには非表示となります。
http://ja.forums.wordpress.org/topic/1056
から情報を得て、少しカスタマイズさせて頂きました。
<?php※ご利用には、K2 themeのクレジットは必ず入れましょう。とのこと。
global $notfound;
if (is_page() and ($notfound != '1')) {
$current_page = $post->ID;
while($current_page) {
$page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$current_page = $page_query->post_parent;
}
$parent_id = $page_query->ID;
$parent_title = $page_query->post_title;
if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status = 'publish'")) {
?>
<div id="subpage">
<ul>
<li class="parentpage"><a href="<?php echo get_permalink($post->post_parent); ?>"><?php echo $parent_title; ?></a>
<ul class="subpage-list">
<?php wp_list_pages('title_li=&child_of='. $parent_id); ?>
</ul></li>
</ul>
</div>
<?php } } ?>
1 コメント: