Skip to content

Instantly share code, notes, and snippets.

@norcross
Forked from crondeau/chilpages-looping.php
Last active December 20, 2015 21:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/6201470 to your computer and use it in GitHub Desktop.
Save norcross/6201470 to your computer and use it in GitHub Desktop.
modified version of child loops
<?php
function rkv_child_pages( $this_page ) {
$args = array(
'fields' => 'ids',
'post_type' => 'work',
'post_parent' => $this_page,
'nopaging' => true,
'orderby' => 'menu_order'
);
$children = get_posts( $args );
if ( !$children )
return false;
return $children;
}
function rkv_subpages( $this_subpage ) {
$args = array(
'fields' => 'ids',
'post_type' => 'work',
'post_parent' => $this_subpage,
'nopaging' => true,
'orderby' => 'menu_order'
);
$subpages = get_posts( $args );
if ( !$subpages )
return false;
return $subpages;
}
// grab all the child pages first
$childpages = rkv_child_pages( $this_page );
// we have nothing. bail.
if ( !$childpages )
return;
// loop through the sub-pages of your custom post type
echo '<section>';
foreach ( $childpages as $child_id ) :
$child_title = get_post_field( 'post_title', $child_id, 'raw' );
$child_content = get_post_field( 'post_content', $child_id, 'raw' );
echo '<h2 class="title"><a href="#">'.$child_title.'</a></h2>';
echo '<div class="content">';
echo wpautop( $child_content );
// now hit our secondary items
$subpages = rkv_subpages( $child_id );
// we have subs. continue on
if ( $subpages ):
foreach ( $subpages as $sub_id ) :
$sub_title = get_post_field( 'post_title', $sub_id, 'raw' );
$sub_content = get_post_field( 'post_content', $sub_id, 'raw' );
echo '<section class="subpages">';
echo '<h3><a href="#">'.$sub_title.'</a></h3>';
echo '<div>';
echo wpautop( $sub_content );
echo '</div>';
echo '</section>';
endforeach;
endif;
echo '</div>'; // end div.content
endforeach;
echo '</section>'; // end section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment