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 
    }
}
Ejemplo n.º 2
0
				<div class="sidebar" role="complementary">
					<?php 
if (get_insection_subnav()) {
    ?>
					<nav class="panel">
						
						<h2>
							<?php 
    wp_reset_postdata();
    link_by_id(get_root_parent_id($post->ID));
    ?>
						</h2>
						<?php 
    insection_subnav('page', 'is-current');
    ?>
					</nav>
					<?php 
}
?>
					<?php 
$sidebar_panels = new WP_Query(array('connected_type' => 'connect_panels', 'connected_items' => get_queried_object_id(), 'nopaging' => true));
if (function_exists('p2p_register_connection_type') && $sidebar_panels->have_posts()) {
    while ($sidebar_panels->have_posts()) {
        $sidebar_panels->the_post();
        ?>
					<article class="panel">
						<?php 
        the_post_thumbnail('panel-thumb', array('class' => '', 'title' => ''));
        ?>
						<h2><?php 
        the_title();