Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi

s-hiroshi/index.php

Created Oct 9, 2012
Embed
What would you like to do?
WordPress > snippet > 子ページのタイトル取得
/**
* スラッグからIDを取得して子ページを取得する。
*/
<?php
$parentPage = get_page_by_path('example');
$parentId = $parentPage->ID;
?>
<ul>
<?php $lastposts = get_posts('post_type=page&posts_per_page=5&post_parent=' . $parentId); ?>
<?php foreach($lastposts as $post) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment