function jc_list_post_children($post_ID, $sub_menu = false) { global $post; /** * The current post of the post children list. * * @since 1.3.0 * @hooked jc_section_program_current_ID 10 */ $current_post_ID = apply_filters('jc_post_children_current_post_ID', $post->ID); $children = get_children(array('post_type' => get_post_type($post_ID), 'post_parent' => $post_ID, 'numberposts' => -1)); // Add parent to beginning array_unshift($children, get_post($post_ID)); /** * Allows filtering of the children to use in the list. * * @since 0.4.0 */ $children = apply_filters('jc_list_post_children_posts', $children); if (!empty($children)) { ?> <ul class="widget-post-children <?php echo $sub_menu ? 'sub-menu' : 'menu'; ?> "> <?php foreach ($children as $post) { ?> <?php setup_postdata($post); ?> <?php $classes = array('menu-item'); $has_children = (bool) get_children(array('post_type' => get_post_type(), 'post_parent' => get_the_ID(), 'numberposts' => 1)); if ($has_children && $post->ID !== $post_ID) { $classes[] = 'menu-item-has-children'; } if ($post->ID == $current_post_ID) { $classes[] = 'current-menu-item'; } ?> <li class="<?php echo implode(' ', $classes); ?> "> <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> </a> <?php if ($has_children && $post->ID !== $post_ID && $sub_menu === false) { jc_list_post_children(get_the_ID(), true); } ?> </li> <?php } ?> <?php wp_reset_postdata(); ?> </ul> <?php } }
/** * Outputs the default page menu. * * @since 1.3.0 */ function jc_page_sidebar_menu($ID = false) { if (!$ID) { $ID = jc_get_top_parent_page_id(); } /** * The ID to use as the parent page. * * @since 1.3.0 */ $ID = apply_filters('jc_page_sidebar_menu_parent_ID', $ID); ?> <li class="jc-page-sidebar"> <?php jc_list_post_children($ID); ?> </li> <?php }