diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 6bd5bddc9..9948d6bba 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -745,6 +745,84 @@ function &get_page(&$page, $output = OBJECT) { } } +function walk_page_tree($pages, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') { + $args = array_slice(func_get_args(), 6); + $parents = array(); + $depth = 0; + $previous_page = ''; + $output = ''; + + $last_page->post_parent = 0; + $last_page->post_id = 0; + $pages[] = $last_page; + + foreach ( $pages as $page ) { + if ( !empty($previous_page) && ($page->post_parent == $previous_page->ID) ) { + // Previous page is my parent. Descend a level. + array_unshift($parents, $page); + $depth++; + if ( !$to_depth || ($depth < $to_depth) ) + if ( !empty($start_level_callback) ) { + $cb_args = array_merge( array($output, $depth), $args); + $output = call_user_func_array($start_level_callback, $cb_args); + } + } else if ( $depth && ($page->post_parent == $parents[0]->ID) ) { + // On the same level as previous page. + if ( !$to_depth || ($depth < $to_depth) ) { + if ( !empty($end_element_callback) ) { + $cb_args = array_merge( array($output, $previous_page, $depth), $args); + $output = call_user_func_array($end_element_callback, $cb_args); + } + } + } else if ( $depth ) { + // Ascend one or more levels. + if ( !$to_depth || ($depth < $to_depth) ) { + if ( !empty($end_element_callback) ) { + $cb_args = array_merge( array($output, $previous_page, $depth), $args); + $output = call_user_func_array($end_element_callback, $cb_args); + } + } + + while ( $parent = array_shift($parents)) { + $depth--; + if ( !$to_depth || ($depth < $to_depth) ) { + if ( !empty($end_level_callback) ) { + $cb_args = array_merge( array($output, $depth), $args); + $output = call_user_func_array($end_level_callback, $cb_args); + } + if ( !empty($end_element_callback) ) { + $cb_args = array_merge( array($output, $parent, $depth), $args); + $output = call_user_func_array($end_element_callback, $cb_args); + } + } + if ( $page->post_parent == $parent->ID ) { + break; + } + } + } else if ( !empty($previous_page) ) { + // Close off previous page. + if ( !$to_depth || ($depth < $to_depth) ) { + if ( !empty($end_element_callback) ) { + $cb_args = array_merge( array($output, $previous_page, $depth), $args); + $output = call_user_func_array($end_element_callback, $cb_args); + } + } + } + + // Start the page. + if ( !$to_depth || ($depth < $to_depth) ) { + if ( !empty($start_element_callback) && ($page->ID != 0) ) { + $cb_args = array_merge( array($output, $page, $depth), $args); + $output = call_user_func_array($start_element_callback, $cb_args); + } + } + + $previous_page = $page; + } + + return $output; +} + function set_category_path($cat) { $cat->fullpath = '/' . $cat->category_nicename; $path = $cat->fullpath; diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index c76e3bd1e..9a1d59399 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -295,7 +295,6 @@ function &get_page_children($page_id, $pages) { function &get_pages($args = '') { global $wpdb; - parse_str($args, $r); if ( !isset($r['child_of']) ) @@ -304,6 +303,8 @@ function &get_pages($args = '') { $r['sort_column'] = 'post_title'; if ( !isset($r['sort_order']) ) $r['sort_order'] = 'ASC'; + if ( !isset($r['hierarchical']) ) + $r['hierarchical'] = 1; $exclusions = ''; if ( !empty($r['exclude']) ) { @@ -327,12 +328,55 @@ function &get_pages($args = '') { // Update cache. update_page_cache($pages); - if ( $r['child_of'] ) + if ( $r['child_of'] || $r['hierarchical'] ) $pages = & get_page_children($r['child_of'], $pages); return $pages; } +function wp_dropdown_pages($args = '') { + parse_str($args, $r); + if ( !isset($r['depth']) ) + $r['depth'] = 0; + if ( !isset($r['child_of']) ) + $r['child_of'] = 0; + if ( !isset($r['echo']) ) + $r['echo'] = 1; + if ( !isset($r['selected']) ) + $r['selected'] = 0; + + extract($r); + + $pages = get_pages($args); + $output = ''; + + if ( ! empty($pages) ) { + $output = "\n"; + } + + $output = apply_filters('wp_dropdown_pages', $output); + + if ( $echo ) + echo $output; + + return $output; +} + +function _page_dropdown_element($output, $page, $depth, $selected) { + $pad = str_repeat(' ', $depth * 3); + + $output .= "\t\n"; + + return $output; +} function wp_list_pages($args = '') { parse_str($args, $r); @@ -340,6 +384,8 @@ function wp_list_pages($args = '') { $r['depth'] = 0; if ( !isset($r['show_date']) ) $r['show_date'] = ''; + if ( !isset($r['date_format']) ) + $r['date_format'] = get_settings('date_format'); if ( !isset($r['child_of']) ) $r['child_of'] = 0; if ( !isset($r['title_li']) ) @@ -350,42 +396,16 @@ function wp_list_pages($args = '') { $output = ''; // Query pages. - $pages = & get_pages($args); - if ( $pages ) { + $pages = get_pages($args); + if ( !empty($pages) ) { if ( $r['title_li'] ) $output .= ''; } @@ -398,51 +418,44 @@ function wp_list_pages($args = '') { return $output; } +function _page_list_level_start($output, $depth) { + $indent = str_repeat("\t", $depth); + $output .= "$indent\n"; + return $output; +} +function _page_list_element_start($output, $page, $depth, $current_page, $show_date, $date_format) { if ( $depth ) $indent = str_repeat("\t", $depth); - //$indent = join('', array_fill(0,$depth,"\t")); - if ( !is_array($page_tree[$parent]['children']) ) - return false; + $css_class = 'page_item'; + if ( $page->ID == $current_page ) + $css_class .= ' current_page_item'; - foreach ( $page_tree[$parent]['children'] as $page_id ) { - $cur_page = $page_tree[$page_id]; - $title = $cur_page['title']; + $output .= $indent . '
  • ' . $page->post_title . ''; - $css_class = 'page_item'; - if ( $page_id == $queried_obj->ID ) - $css_class .= ' current_page_item'; + if ( !empty($show_date) ) { + if ( 'modified' == $show_date ) + $time = $page->post_modified; + else + $time = $page->post_date; - $output .= $indent . '
  • ' . $title . ''; - - if ( isset($cur_page['ts']) ) { - $format = get_settings('date_format'); - if ( isset($args['date_format']) ) - $format = $args['date_format']; - $output .= " " . mysql2date($format, $cur_page['ts']); - } - - if ( isset($cur_page['children']) && is_array($cur_page['children']) ) { - $new_depth = $depth + 1; - - if ( !$args['depth'] || $depth < ($args['depth']-1) ) { - $output .= "$indent\n"; - } - } - $output .= "$indent
  • \n"; + $output .= " " . mysql2date($date_format, $time); } - if ( $echo ) - echo $output; - else - return $output; + + return $output; +} + +function _page_list_element_end($output, $page, $depth) { + $output .= "\n"; + + return $output; } function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {