function insection_subnav($post_type = 'page', $current_class = 'current_page_item') { // Test if current page in sub navigation // ------------------------------------------------------------- function subnav_is_current($post_id) { global $post; return $post_id == $post->ID; } // Test next level in sub navigation // ------------------------------------------------------------- function subnav_next_level($post_id, $next_level) { global $post; if ($post->ancestors == null) { $post_ancestors = array(); } else { $post_ancestors = $post->ancestors; } return $next_level && subnav_is_current($post_id) || in_array($post_id, $post_ancestors); } // Test for subnav // ------------------------------------------------------------- $sub_level_1 = get_insection_subnav($post_type); // Output subnav // ------------------------------------------------------------- // level 1 if ($sub_level_1) { ?> <ul class="nav-secondary level-1"> <?php // level 1 items foreach ($sub_level_1 as $level_1_page) { $level_1_page_id = $level_1_page->ID; ?> <li class="level-1-item<?php echo subnav_is_current($level_1_page_id) ? ' ' . $current_class . '' : ''; ?> "> <?php link_by_id($level_1_page_id); ?> <?php // level 2 $sub_level_2 = get_sub_pages($level_1_page_id, $post_type); if (subnav_next_level($level_1_page_id, $sub_level_2)) { ?> <ul class="level-2"> <?php // level 2 items foreach ($sub_level_2 as $level_2_page) { $level_2_page_id = $level_2_page->ID; ?> <li class="level-2-item<?php echo subnav_is_current($level_2_page_id) ? ' ' . $current_class . '' : ''; ?> "> <?php link_by_id($level_2_page_id); ?> <?php // level 3 $sub_level_3 = get_sub_pages($level_2_page_id, $post_type); if (subnav_next_level($level_2_page_id, $sub_level_3)) { ?> <ul class="level-3"> <?php // level 3 items foreach ($sub_level_3 as $level_3_page) { $level_3_page_id = $level_3_page->ID; ?> <li class="level-3-item<?php echo subnav_is_current($level_3_page_id) ? ' ' . $current_class . '' : ''; ?> "> <?php link_by_id($level_3_page_id); ?> </li> <?php // level 3 items } ?> </ul> <?php // level 3 } ?> </li> <?php // level 2 items } ?> </ul> <?php // level 2 } ?> </li> <?php // level 1 items } ?> </ul> <?php } }
get_template_part('parts/page-title'); ?> <?php while (have_posts()) { the_post(); ?> <?php the_content(); ?> <?php } ?> <?php // Output sub pages of current page $sub_pages = get_sub_pages($post->ID); if ($sub_pages) { ?> <section class="index"> <?php foreach ($sub_pages as $page) { ?> <article class="entry"> <div class="entry-body media cf"> <?php if (has_post_thumbnail($page->ID)) { ?> <div class="media-img"> <?php my_the_post_thumbnail($page->ID, 'index-thumb'); ?>