-
-
Save norcross/6201470 to your computer and use it in GitHub Desktop.
modified version of child loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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