Skip to content

Instantly share code, notes, and snippets.



Created Oct 9, 2012
What would you like to do?
WordPress > snippet > 子ページのタイトル取得
* スラッグからIDを取得して子ページを取得する。
$parentPage = get_page_by_path('example');
$parentId = $parentPage->ID;
<?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(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment