Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Created October 23, 2013 18:37
Show Gist options
  • Save barbwiredmedia/7124127 to your computer and use it in GitHub Desktop.
Save barbwiredmedia/7124127 to your computer and use it in GitHub Desktop.
Wordpress Temples: This creates a conditional based on the parent page ID. If ( specific page || checks for existence of having our parent page || looks for all ancestors of our parent and limits it to those children only ) The query brings back posts that are children of our parent.
<?php
//Set up the variables of the parent page ID's
$parentPageID = '509';
?>
<?php if (is_page($parentPageID) || $post->post_parent == $parentPageID || ($post->ancestors && in_array($parentPageID, $post->ancestors) )) { ?>
<h3>Child Pages</h3>
<ul>
<?php
//Queries for all pages that are children of our parent ID
?>
<?php
query_posts(array('showposts' => 5, 'post_parent' => $parentPageID, 'post_type' => 'page'));
while (have_posts()) {
the_post();
?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php } ?>
<?php wp_reset_query(); ?>
</ul>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment