Example #1
0
 function start_el(&$output, $page, $depth, $args, $current_page)
 {
     if ($depth) {
         $indent = str_repeat("\t", $depth);
     } else {
         $indent = '';
     }
     extract($args, EXTR_SKIP);
     $css_class = array('page_item', 'page-item-' . $page->ID);
     if (!empty($current_page)) {
         $_current_page = get_page($current_page);
         _get_post_ancestors($_current_page);
         if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) {
             $css_class[] = 'current_page_ancestor';
         }
         if ($page->ID == $current_page) {
             $css_class[] = 'current_page_item bodyguard';
             // added bodyguard class to prevent current_page_item class from being removed
             //Span injection sent to $output if active page
             $active_arrow = '<span class="active"></span>';
         } elseif ($_current_page && $page->ID == $_current_page->post_parent) {
             $css_class[] = 'current_page_parent';
         }
     } elseif ($page->ID == get_option('page_for_posts')) {
         $css_class[] = 'current_page_parent';
     }
     $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
     $output .= $indent . '<li class="' . $css_class . '">' . $active_arrow . '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(wp_strip_all_tags(apply_filters('the_title', $page->post_title, $page->ID))) . '">' . $link_before . apply_filters('the_title', $page->post_title, $page->ID) . $link_after . '</a>';
 }
Example #2
0
 /**
  * @see Walker::start_el()
  * @since 2.1.0
  *
  * @param string $output Passed by reference. Used to append additional content.
  * @param object $page Page data object.
  * @param int $depth Depth of page. Used for padding.
  * @param int $current_page Page ID.
  * @param array $args
  */
 function start_el(&$output, $page, $depth, $args, $current_page = 0)
 {
     if ($depth) {
         $indent = str_repeat("\t", $depth);
     } else {
         $indent = '';
     }
     extract($args, EXTR_SKIP);
     $css_class = array('page_item', 'page-item-' . $page->ID);
     if (!empty($current_page)) {
         $_current_page = get_page($current_page);
         _get_post_ancestors($_current_page);
         if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) {
             $css_class[] = 'current_page_ancestor';
         }
         if ($page->ID == $current_page) {
             $css_class[] = 'current_page_item';
         } elseif ($_current_page && $page->ID == $_current_page->post_parent) {
             $css_class[] = 'current_page_parent';
         }
     } elseif ($page->ID == get_option('page_for_posts')) {
         $css_class[] = 'current_page_parent';
     }
     //判断是否有二级菜单,增加二级的属性和class
     $children = get_pages("child_of=" . $page->ID);
     $has_children = count($children) != 0 ? true : false;
     $li_attributes = '';
     $a_class = '';
     if ($has_children) {
         $css_class[] = 1 > $depth ? 'dropdown' : 'dropdown-submenu';
         $li_attributes .= ' data-dropdown="dropdown"';
         $a_class = ' class="dropdown-toggle" data-toggle="dropdown"';
         $link_after = '<b class="caret"></b>';
     }
     $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page, $depth, $args, $current_page));
     //设置li的class
     $output .= $indent . '<li class="' . $css_class . '" ' . $li_attributes . '><a ' . $a_class . ' href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters('the_title', $page->post_title, $page->ID) . $link_after . '</a>';
     if (!empty($show_date)) {
         if ('modified' == $show_date) {
             $time = $page->post_modified;
         } else {
             $time = $page->post_date;
         }
         $output .= " " . mysql2date($date_format, $time);
     }
 }
 function start_el(&$output, $page, $depth, $args, $current_page)
 {
     if ($depth) {
         $indent = str_repeat("\t", $depth);
     } else {
         $indent = '';
     }
     extract($args, EXTR_SKIP);
     $css_class = array('item', 'item-' . $page->ID);
     $css_class[] = get_post_type($page->ID);
     if (!empty($current_page)) {
         $_current_page = get_page($current_page);
         _get_post_ancestors($_current_page);
         if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) {
             $css_class[] = 'current_ancestor';
         }
         if ($page->ID == $current_page) {
             $css_class[] = 'current_item';
         } elseif ($_current_page && $page->ID == $_current_page->post_parent) {
             $css_class[] = 'current_parent';
         }
     } elseif ($page->ID == get_option('page_for_posts')) {
         $css_class[] = 'current_parent';
     }
     $css_class[] = $page->post_status;
     if ($page->ID == get_the_ID()) {
         $css_class[] = 'current_item';
     }
     if (isset($selected_items) && is_array($selected_items) && in_array($page->ID, $selected_items)) {
         $css_class[] = 'current_item';
     }
     $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page, $depth, $args, $current_page));
     $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '"><i></i>' . $link_before . apply_filters('the_title', $page->post_title, $page->ID) . $link_after . '</a>';
     if (!empty($show_date)) {
         if ('modified' == $show_date) {
             $time = $page->post_modified;
         } else {
             $time = $page->post_date;
         }
         $output .= " " . mysql2date($date_format, $time);
     }
 }
Example #4
0
/**
 * Retrieves post data given a post ID or post object.
 *
 * See {@link sanitize_post()} for optional $filter values. Also, the parameter
 * $post, must be given as a variable, since it is passed by reference.
 *
 * @since 1.5.1
 * @uses $wpdb
 * @link http://codex.wordpress.org/Function_Reference/get_post
 *
 * @param int|object $post Post ID or post object.
 * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
 * @param string $filter Optional, default is raw.
 * @return mixed Post data
 */
function &get_post(&$post, $output = OBJECT, $filter = 'raw')
{
    global $wpdb;
    $null = null;
    if (empty($post)) {
        if (isset($GLOBALS['post'])) {
            $_post =& $GLOBALS['post'];
        } else {
            return $null;
        }
    } elseif (is_object($post) && empty($post->filter)) {
        _get_post_ancestors($post);
        $_post = sanitize_post($post, 'raw');
        wp_cache_add($post->ID, $_post, 'posts');
    } else {
        if (is_object($post)) {
            $post_id = $post->ID;
        } else {
            $post_id = $post;
        }
        $post_id = (int) $post_id;
        if (!($_post = wp_cache_get($post_id, 'posts'))) {
            $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d LIMIT 1", $post_id));
            if (!$_post) {
                return $null;
            }
            _get_post_ancestors($_post);
            $_post = sanitize_post($_post, 'raw');
            wp_cache_add($_post->ID, $_post, 'posts');
        }
    }
    if ($filter != 'raw') {
        $_post = sanitize_post($_post, $filter);
    }
    if ($output == OBJECT) {
        return $_post;
    } elseif ($output == ARRAY_A) {
        $__post = get_object_vars($_post);
        return $__post;
    } elseif ($output == ARRAY_N) {
        $__post = array_values(get_object_vars($_post));
        return $__post;
    } else {
        return $_post;
    }
}
/**
 * Add the class property classes for the current context, if applicable.
 *
 * @access private
 * @since 3.0
 *
 * @param array $menu_items The current menu item objects to which to add the class property information.
 */
function _wp_menu_item_classes_by_context(&$menu_items)
{
    global $wp_query;
    $queried_object = $wp_query->get_queried_object();
    $queried_object_id = (int) $wp_query->queried_object_id;
    $active_object = '';
    $active_ancestor_item_ids = array();
    $active_parent_item_ids = array();
    $active_parent_object_ids = array();
    $possible_taxonomy_ancestors = array();
    $possible_object_parents = array();
    $home_page_id = (int) get_option('page_for_posts');
    if ($wp_query->is_singular && !empty($queried_object->post_type) && !is_post_type_hierarchical($queried_object->post_type)) {
        foreach ((array) get_object_taxonomies($queried_object->post_type) as $taxonomy) {
            if (is_taxonomy_hierarchical($taxonomy)) {
                $term_hierarchy = _get_term_hierarchy($taxonomy);
                $terms = wp_get_object_terms($queried_object_id, $taxonomy, array('fields' => 'ids'));
                if (is_array($terms)) {
                    $possible_object_parents = array_merge($possible_object_parents, $terms);
                    $term_to_ancestor = array();
                    foreach ((array) $term_hierarchy as $anc => $descs) {
                        foreach ((array) $descs as $desc) {
                            $term_to_ancestor[$desc] = $anc;
                        }
                    }
                    foreach ($terms as $desc) {
                        do {
                            $possible_taxonomy_ancestors[$taxonomy][] = $desc;
                            if (isset($term_to_ancestor[$desc])) {
                                $_desc = $term_to_ancestor[$desc];
                                unset($term_to_ancestor[$desc]);
                                $desc = $_desc;
                            } else {
                                $desc = 0;
                            }
                        } while (!empty($desc));
                    }
                }
            }
        }
    } elseif (!empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type)) {
        _get_post_ancestors($queried_object);
    } elseif (!empty($queried_object->taxonomy) && is_taxonomy_hierarchical($queried_object->taxonomy)) {
        $term_hierarchy = _get_term_hierarchy($queried_object->taxonomy);
        $term_to_ancestor = array();
        foreach ((array) $term_hierarchy as $anc => $descs) {
            foreach ((array) $descs as $desc) {
                $term_to_ancestor[$desc] = $anc;
            }
        }
        $desc = $queried_object->term_id;
        do {
            $possible_taxonomy_ancestors[$queried_object->taxonomy][] = $desc;
            if (isset($term_to_ancestor[$desc])) {
                $_desc = $term_to_ancestor[$desc];
                unset($term_to_ancestor[$desc]);
                $desc = $_desc;
            } else {
                $desc = 0;
            }
        } while (!empty($desc));
    }
    $possible_object_parents = array_filter($possible_object_parents);
    $front_page_url = home_url();
    foreach ((array) $menu_items as $key => $menu_item) {
        $menu_items[$key]->current = false;
        $classes = (array) $menu_item->classes;
        $classes[] = 'menu-item';
        $classes[] = 'menu-item-type-' . $menu_item->type;
        $classes[] = 'menu-item-object-' . $menu_item->object;
        // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
        if ($wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array($menu_item->object_id, $possible_object_parents)) {
            $active_parent_object_ids[] = (int) $menu_item->object_id;
            $active_parent_item_ids[] = (int) $menu_item->db_id;
            $active_object = $queried_object->post_type;
            // if the menu item corresponds to the currently-queried post or taxonomy object
        } elseif ($menu_item->object_id == $queried_object_id && (!empty($home_page_id) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id || 'post_type' == $menu_item->type && $wp_query->is_singular || 'taxonomy' == $menu_item->type && ($wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax))) {
            $classes[] = 'current-menu-item';
            $menu_items[$key]->current = true;
            $_anc_id = (int) $menu_item->db_id;
            while (($_anc_id = get_post_meta($_anc_id, '_menu_item_menu_item_parent', true)) && !in_array($_anc_id, $active_ancestor_item_ids)) {
                $active_ancestor_item_ids[] = $_anc_id;
            }
            if ('post_type' == $menu_item->type && 'page' == $menu_item->object) {
                // Back compat classes for pages to match wp_page_menu()
                $classes[] = 'page_item';
                $classes[] = 'page-item-' . $menu_item->object_id;
                $classes[] = 'current_page_item';
            }
            $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
            $active_parent_object_ids[] = (int) $menu_item->post_parent;
            $active_object = $menu_item->object;
            // if the menu item corresponds to the currently-requested URL
        } elseif ('custom' == $menu_item->object) {
            $current_url = untrailingslashit((is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
            $item_url = untrailingslashit(strpos($menu_item->url, '#') ? substr($menu_item->url, 0, strpos($menu_item->url, '#')) : $menu_item->url);
            $_indexless_current = untrailingslashit(preg_replace('/index.php$/', '', $current_url));
            if (in_array($item_url, array($current_url, $_indexless_current))) {
                $classes[] = 'current-menu-item';
                $menu_items[$key]->current = true;
                $_anc_id = (int) $menu_item->db_id;
                while (($_anc_id = get_post_meta($_anc_id, '_menu_item_menu_item_parent', true)) && !in_array($_anc_id, $active_ancestor_item_ids)) {
                    $active_ancestor_item_ids[] = $_anc_id;
                }
                if (in_array(home_url(), array(untrailingslashit($current_url), untrailingslashit($_indexless_current)))) {
                    // Back compat for home link to match wp_page_menu()
                    $classes[] = 'current_page_item';
                }
                $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
                $active_parent_object_ids[] = (int) $menu_item->post_parent;
                $active_object = $menu_item->object;
                // give front page item current-menu-item class when extra query arguments involved
            } elseif ($item_url == $front_page_url && is_front_page()) {
                $classes[] = 'current-menu-item';
            }
            if (untrailingslashit($item_url) == home_url()) {
                $classes[] = 'menu-item-home';
            }
        }
        // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
        if (!empty($home_page_id) && 'post_type' == $menu_item->type && empty($wp_query->is_page) && $home_page_id == $menu_item->object_id) {
            $classes[] = 'current_page_parent';
        }
        $menu_items[$key]->classes = array_unique($classes);
    }
    $active_ancestor_item_ids = array_filter(array_unique($active_ancestor_item_ids));
    $active_parent_item_ids = array_filter(array_unique($active_parent_item_ids));
    $active_parent_object_ids = array_filter(array_unique($active_parent_object_ids));
    // set parent's class
    foreach ((array) $menu_items as $key => $parent_item) {
        $classes = (array) $parent_item->classes;
        $menu_items[$key]->current_item_ancestor = false;
        $menu_items[$key]->current_item_parent = false;
        if (isset($parent_item->type) && ('post_type' == $parent_item->type && !empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type) && in_array($parent_item->object_id, $queried_object->ancestors) && $parent_item->object != $queried_object->ID || 'taxonomy' == $parent_item->type && isset($possible_taxonomy_ancestors[$parent_item->object]) && in_array($parent_item->object_id, $possible_taxonomy_ancestors[$parent_item->object]) && (!isset($queried_object->term_id) || $parent_item->object_id != $queried_object->term_id))) {
            $classes[] = empty($queried_object->taxonomy) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor';
        }
        if (in_array(intval($parent_item->db_id), $active_ancestor_item_ids)) {
            $classes[] = 'current-menu-ancestor';
            $menu_items[$key]->current_item_ancestor = true;
        }
        if (in_array($parent_item->db_id, $active_parent_item_ids)) {
            $classes[] = 'current-menu-parent';
            $menu_items[$key]->current_item_parent = true;
        }
        if (in_array($parent_item->object_id, $active_parent_object_ids)) {
            $classes[] = 'current-' . $active_object . '-parent';
        }
        if ('post_type' == $parent_item->type && 'page' == $parent_item->object) {
            // Back compat classes for pages to match wp_page_menu()
            if (in_array('current-menu-parent', $classes)) {
                $classes[] = 'current_page_parent';
            }
            if (in_array('current-menu-ancestor', $classes)) {
                $classes[] = 'current_page_ancestor';
            }
        }
        $menu_items[$key]->classes = array_unique($classes);
    }
}
Example #6
0
/**
 * Retrieve ancestors of a post.
 *
 * @since 2.5.0
 *
 * @param int|object $post Post ID or post object
 * @return array Ancestor IDs or empty array if none are found.
 */
function get_post_ancestors($post)
{
    $post = get_post($post);
    if (!isset($post->ancestors)) {
        _get_post_ancestors($post);
    }
    if (!empty($post->ancestors)) {
        return $post->ancestors;
    }
    return array();
}
Example #7
0
function _mystique_menu_item_classes_by_context(&$menu_items)
{
    global $wp_query;
    $queried_object = $wp_query->get_queried_object();
    $queried_object_id = (int) $wp_query->queried_object_id;
    $active_object = '';
    $active_parent_item_ids = array();
    $active_parent_object_ids = array();
    $possible_object_parents = array();
    $home_page_id = (int) get_option('page_for_posts');
    if ($wp_query->is_singular && !empty($queried_object->post_type) && !is_post_type_hierarchical($queried_object->post_type)) {
        foreach ((array) get_object_taxonomies($queried_object->post_type) as $taxonomy) {
            if (is_taxonomy_hierarchical($taxonomy)) {
                $terms = wp_get_object_terms($queried_object_id, $taxonomy, array('fields' => 'ids'));
                if (is_array($terms)) {
                    $possible_object_parents = array_merge($possible_object_parents, $terms);
                }
            }
        }
    } elseif (!empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type)) {
        _get_post_ancestors($queried_object);
    }
    $possible_object_parents = array_filter($possible_object_parents);
    foreach ((array) $menu_items as $key => $menu_item) {
        // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
        if ($wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array($menu_item->object_id, $possible_object_parents)) {
            $active_parent_object_ids[] = (int) $menu_item->object_id;
            $active_parent_item_ids[] = (int) $menu_item->db_id;
            $active_object = $queried_object->post_type;
            // if the menu item corresponds to the currently-queried post or taxonomy object
        } elseif ($menu_item->object_id == $queried_object_id && (!empty($home_page_id) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id || 'post_type' == $menu_item->type && $wp_query->is_singular || 'taxonomy' == $menu_item->type && ($wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax))) {
            $menu_items[$key]->classes[] = 'active';
            $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
            $active_parent_object_ids[] = (int) $menu_item->post_parent;
            $active_object = $menu_item->object;
            // if the menu item corresponds to the currently-requested URL
        } elseif ('custom' == $menu_item->object) {
            $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
            $item_url = strpos($menu_item->url, '#') ? substr($menu_item->url, 0, strpos($menu_item->url, '#')) : $menu_item->url;
            if ($item_url == $current_url) {
                $menu_items[$key]->classes[] = 'active';
                if (untrailingslashit($current_url) == home_url()) {
                    $menu_items[$key]->classes[] = 'home';
                }
                $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
                $active_parent_object_ids[] = (int) $menu_item->post_parent;
                $active_object = $menu_item->object;
            }
        }
        // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
        if (!empty($home_page_id) && 'post_type' == $menu_item->type && empty($wp_query->is_page) && $home_page_id == $menu_item->object_id) {
            $menu_items[$key]->classes[] = 'active-parent';
        }
    }
    $active_parent_item_ids = array_filter(array_unique($active_parent_item_ids));
    $active_parent_object_ids = array_filter(array_unique($active_parent_object_ids));
    // set parent's class
    foreach ((array) $menu_items as $key => $parent_item) {
        if (isset($parent_item->type) && 'post_type' == $parent_item->type && !empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type) && in_array($parent_item->object_id, $queried_object->ancestors)) {
            $menu_items[$key]->classes[] = 'active-' . $queried_object->post_type . '-ancestor active-ancestor';
        }
        if (in_array($parent_item->db_id, $active_parent_item_ids)) {
            $menu_items[$key]->classes[] = 'active-parent';
        }
        if (in_array($parent_item->object_id, $active_parent_object_ids)) {
            $menu_items[$key]->classes[] = 'active-' . $active_object . '-parent';
        }
    }
}
 /**
  * @see Walker::start_el()
  * @since 2.1.0
  *
  * @param string $output Passed by reference. Used to append additional content.
  * @param object $page Page data object.
  * @param int $depth Depth of page. Used for padding.
  * @param int $current_page Page ID.
  * @param array $args
  */
 function start_el(&$output, $page, $depth, $args, $current_page)
 {
     if ($depth) {
         $indent = str_repeat("\t", $depth);
     } else {
         $indent = '';
     }
     extract($args, EXTR_SKIP);
     $css_class = array('nav-' . $page->post_name);
     if (!empty($current_page)) {
         $_current_page = get_page($current_page);
         _get_post_ancestors($_current_page);
         if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) {
             $css_class[] = 'open';
         }
         if ($page->ID == $current_page) {
             $css_class[] = 'active';
         } elseif ($_current_page && $page->ID == $_current_page->post_parent) {
             $css_class[] = 'parent';
         }
     } elseif ($page->ID == get_option('page_for_posts')) {
         $css_class[] = 'post-parent';
     }
     $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
     $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '" title="' . esc_attr(wp_strip_all_tags(apply_filters('the_title', $page->post_title, $page->ID))) . '">' . $link_before . apply_filters('the_title', $page->post_title, $page->ID) . $link_after . '</a>';
     if (!empty($show_date)) {
         if ('modified' == $show_date) {
             $time = $page->post_modified;
         } else {
             $time = $page->post_date;
         }
         $output .= " " . mysql2date($date_format, $time);
     }
 }
/**
 * get_post() - Retrieves post data given a post ID or post object.
 *
 * {@internal Missing Long Description}}
 *
 * @package WordPress
 * @subpackage Post
 * @since 1.5.1
 * @uses $wpdb
 *
 * @param int|object &$post post ID or post object
 * @param string $output {@internal Missing Description}}
 * @param string $filter {@internal Missing Description}}
 * @return mixed {@internal Missing Description}}
 */
function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
	global $wpdb;
	$null = null;

	if ( empty($post) ) {
		if ( isset($GLOBALS['post']) )
			$_post = & $GLOBALS['post'];
		else
			return $null;
	} elseif ( is_object($post) ) {
		wp_cache_add($post->ID, $post, 'posts');
		$_post = &$post;
	} else {
		$post = (int) $post;
		if ( ! $_post = wp_cache_get($post, 'posts') ) {
			$_post = & $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
			wp_cache_add($_post->ID, $_post, 'posts');
		}
	}

	// Populate the ancestors field.
	// Not cached since we don't clear cache for ancestors when a post changes.
	_get_post_ancestors($_post);

	$_post = sanitize_post($_post, $filter);

	if ( $output == OBJECT ) {
		return $_post;
	} elseif ( $output == ARRAY_A ) {
		$__post = get_object_vars($_post);
		return $__post;
	} elseif ( $output == ARRAY_N ) {
		$__post = array_values(get_object_vars($_post));
		return $__post;
	} else {
		return $_post;
	}
}
Example #10
0
 function widget($args, $instance)
 {
     extract($args);
     global $post;
     if (is_search() || is_404()) {
         return false;
     }
     //doesn't apply to search or 404 page
     if (is_front_page() && !$instance['show_on_home']) {
         return false;
     }
     //if we're on the front page and we haven't chosen to show this anyways, leave
     if (is_page()) {
         if (isset($post) && is_object($post)) {
             _get_post_ancestors($post);
         }
         //workaround for occassional problems
     } else {
         if ($post_page = get_option("page_for_posts")) {
             $post = get_page($post_page);
         } elseif ($instance['show_on_home']) {
             $sub_front_page = true;
         } else {
             return false;
         }
     }
     if (is_front_page() || isset($sub_front_page)) {
         echo $before_widget . $before_title . get_bloginfo('name') . $after_title . "<ul>";
         $children = wp_list_pages(array('title_li' => '', 'depth' => 1, 'sort_column' => $instance['sort_by'], 'exclude' => $instance['exclude'], 'echo' => false));
         echo apply_filters('simple_section_page_list', $children);
         echo "</ul>" . $after_widget;
         return true;
     }
     $exclude_list = $instance['exclude'];
     $excluded = explode(',', $exclude_list);
     //convert list of excluded pages to array
     if (in_array($post->ID, $excluded) && $instance['hide_on_excluded']) {
         return false;
     }
     //if on excluded page, and setup to hide on excluded pages
     $post_ancestors = isset($post->ancestors) ? $post->ancestors : get_post_ancestors($post);
     //get the current page's ancestors either from existing value or by executing function
     $top_page = $post_ancestors ? end($post_ancestors) : $post->ID;
     //get the top page id
     $thedepth = 0;
     //initialize default variables
     if (!$instance['show_all']) {
         $ancestors_me = implode(',', $post_ancestors) . ',' . $post->ID;
         //exclude pages not in direct hierarchy
         foreach ($post_ancestors as $anc_id) {
             if (in_array($anc_id, $excluded) && $instance['hide_on_excluded']) {
                 return false;
             }
             //if ancestor excluded, and hide on excluded, leave
             $pageset = get_pages(array('child_of' => $anc_id, 'parent' => $anc_id, 'exclude' => $ancestors_me));
             foreach ($pageset as $page) {
                 $excludeset = get_pages(array('child_of' => $page->ID, 'parent' => $page->ID));
                 foreach ($excludeset as $expage) {
                     $exclude_list .= ',' . $expage->ID;
                 }
             }
         }
         $thedepth = count($post_ancestors) + 1;
         //prevents improper grandchildren from showing
     }
     $children = wp_list_pages(array('title_li' => '', 'echo' => 0, 'depth' => $thedepth, 'child_of' => $top_page, 'sort_column' => $instance['sort_by'], 'exclude' => $exclude_list));
     //get the list of pages, including only those in our page list
     if (!$children && !$instance['show_empty']) {
         return false;
     }
     //if there are no pages in this section, and use hasnt chosen to display widget anyways, leave the function
     $sect_title = $instance['title'] ? apply_filters('the_title', $instance['title']) : apply_filters('the_title', get_the_title($top_page), $top_page);
     $sect_title = apply_filters('simple_section_nav_title', $sect_title);
     if ($instance['a_heading']) {
         $headclass = $post->ID == $top_page ? "current_page_item" : "current_page_ancestor";
         if ($post->post_parent == $top_page) {
             $headclass .= " current_page_parent";
         }
         $sect_title = '<a href="' . get_page_link($top_page) . '" id="toppage-' . $top_page . '" class="' . $headclass . '">' . $sect_title . '</a>';
     }
     echo $before_widget . $before_title . $sect_title . $after_title . "<ul>";
     echo apply_filters('simple_section_page_list', $children);
     echo "</ul>" . $after_widget;
 }