Skip to content

Instantly share code, notes, and snippets.

@benbrandt
Last active August 29, 2015 14:18
Show Gist options
  • Save benbrandt/3fe20a032c0bd2bd25e7 to your computer and use it in GitHub Desktop.
Save benbrandt/3fe20a032c0bd2bd25e7 to your computer and use it in GitHub Desktop.
Pull Child Page Content into Parent Page - WordPress
<div class="entry-content">
<?php the_content(); ?>
<?php
$childArgs = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'child_of' => get_the_ID()
);
$childList = get_pages($childArgs);
foreach ($childList as $child) { ?>
<div class="child-page">
<h2 class="child-title"><?php echo $child->post_title; ?></h2>
<?php echo apply_filters( 'the_content', $child->post_content); ?>
</div>
<?php } ?>
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc&parent=0');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<ul class="page-nav">
<?php if (!empty($prevID)) { ?>
<li class="previous">
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>"><span aria-hidden="true">&larr;</span> <?php echo get_the_title($prevID); ?></a>
</li>
<?php }
if (!empty($nextID)) { ?>
<li class="next">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?> <span aria-hidden="true">&rarr;</span></a>
</li>
<?php } ?>
</ul><!-- .navigation -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment