Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created October 9, 2012 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/3858123 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3858123 to your computer and use it in GitHub Desktop.
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