summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-includes/template-functions-post.php
diff options
context:
space:
mode:
authormatt <matt@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-05-15 03:19:56 +0000
committermatt <matt@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-05-15 03:19:56 +0000
commit034694eb53dd71a980745f5594509890fd761998 (patch)
treec85517e8af3fce163f1d183afdf7c9ac7094d84e /wp-inst/wp-includes/template-functions-post.php
parenta72266931b88c8fa300d2e29a69a2bb38a70654a (diff)
Lots and lots of changes.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@543 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst/wp-includes/template-functions-post.php')
-rw-r--r--wp-inst/wp-includes/template-functions-post.php214
1 files changed, 100 insertions, 114 deletions
diff --git a/wp-inst/wp-includes/template-functions-post.php b/wp-inst/wp-includes/template-functions-post.php
index ed06b74..461d6e5 100644
--- a/wp-inst/wp-includes/template-functions-post.php
+++ b/wp-inst/wp-includes/template-functions-post.php
@@ -15,6 +15,10 @@ function the_ID() {
echo $id;
}
+function get_the_ID() {
+ global $id;
+ return $id;
+}
function the_title($before = '', $after = '', $echo = true) {
$title = get_the_title();
@@ -274,6 +278,17 @@ function the_meta() {
Pages
*/
+function walk_page_tree() {
+ $walker = new Walker_Page;
+ $args = func_get_args();
+ return call_user_func_array(array(&$walker, 'walk'), $args);
+}
+
+function walk_page_dropdown_tree() {
+ $walker = new Walker_PageDropdown;
+ $args = func_get_args();
+ return call_user_func_array(array(&$walker, 'walk'), $args);
+}
function &get_page_children($page_id, $pages) {
global $page_cache;
@@ -296,38 +311,58 @@ function &get_page_children($page_id, $pages) {
function &get_pages($args = '') {
global $wpdb;
- parse_str($args, $r);
-
- if ( !isset($r['child_of']) )
- $r['child_of'] = 0;
- if ( !isset($r['sort_column']) )
- $r['sort_column'] = 'post_title';
- if ( !isset($r['sort_order']) )
- $r['sort_order'] = 'ASC';
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
+
+ $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
+ 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '');
+ $r = array_merge($defaults, $r);
+ extract($r);
+
+ $inclusions = '';
+ if ( !empty($include) ) {
+ $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include
+ $exclude = '';
+ $meta_key = '';
+ $meta_value = '';
+ $incpages = preg_split('/[\s,]+/',$include);
+ if ( count($incpages) ) {
+ foreach ( $incpages as $incpage ) {
+ if (empty($inclusions))
+ $inclusions = ' AND ( ID = ' . intval($incpage) . ' ';
+ else
+ $inclusions .= ' OR ID = ' . intval($incpage) . ' ';
+ }
+ }
+ }
+ if (!empty($inclusions))
+ $inclusions .= ')';
$exclusions = '';
- if ( !empty($r['exclude']) ) {
- $expages = preg_split('/[\s,]+/',$r['exclude']);
+ if ( !empty($exclude) ) {
+ $expages = preg_split('/[\s,]+/',$exclude);
if ( count($expages) ) {
foreach ( $expages as $expage ) {
- $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
+ if (empty($exclusions))
+ $exclusions = ' AND ( ID <> ' . intval($expage) . ' ';
+ else
+ $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
}
}
}
+ if (!empty($exclusions))
+ $exclusions .= ')';
- $q = "SELECT * " .
- "FROM $wpdb->posts " .
- "WHERE post_type = 'page' AND post_status = 'publish' " .
- "$exclusions " .
- "ORDER BY " . $r['sort_column'] . " " . $r['sort_order'];
+ $query = "SELECT * FROM $wpdb->posts " ;
+ $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;
+ $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ;
+ $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ;
+ $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
- $cached_pages = wp_cache_get( md5( $q ), 'general');
- if ( is_array( $cached_pages ) == false || ( is_array( $cached_pages ) == true && ( get_option( 'pages_last_updated' ) != false && $cached_pages[ 'time' ] < get_option( 'pages_last_updated' ) ) ) ) {
- $pages = $wpdb->get_results($q);
- wp_cache_set( md5( $q ), array( 'pages' => $pages, 'time' => time() ), 'general', 600 );
- } else {
- $pages = $cached_pages[ 'pages' ];
- }
+ $pages = $wpdb->get_results($query);
+ $pages = apply_filters('get_pages', $pages, $r);
if ( empty($pages) )
return array();
@@ -335,119 +370,70 @@ function &get_pages($args = '') {
// Update cache.
update_page_cache($pages);
- if ( $r['child_of'] )
- $pages = & get_page_children($r['child_of'], $pages);
+ if ( $child_of || $hierarchical )
+ $pages = & get_page_children($child_of, $pages);
return $pages;
}
+function wp_dropdown_pages($args = '') {
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
-function wp_list_pages($args = '') {
- parse_str($args, $r);
- if ( !isset($r['depth']) )
- $r['depth'] = 0;
- if ( !isset($r['show_date']) )
- $r['show_date'] = '';
- if ( !isset($r['child_of']) )
- $r['child_of'] = 0;
- if ( !isset($r['title_li']) )
- $r['title_li'] = __('Pages');
- if ( !isset($r['echo']) )
- $r['echo'] = 1;
+ $defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1,
+ 'name' => 'page_id');
+ $r = array_merge($defaults, $r);
+ extract($r);
+ $pages = get_pages($r);
$output = '';
- // Query pages.
- $pages = & get_pages($args);
- if ( $pages ) {
-
- if ( $r['title_li'] )
- $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
-
- // Now loop over all pages that were selected
- $page_tree = Array();
- foreach ( $pages as $page ) {
- // set the title for the current page
- $page_tree[$page->ID]['title'] = $page->post_title;
- $page_tree[$page->ID]['name'] = $page->post_name;
-
- // set the selected date for the current page
- // depending on the query arguments this is either
- // the createtion date or the modification date
- // as a unix timestamp. It will also always be in the
- // ts field.
- if ( !empty($r['show_date']) ) {
- if ( 'modified' == $r['show_date'] )
- $page_tree[$page->ID]['ts'] = $page->post_modified;
- else
- $page_tree[$page->ID]['ts'] = $page->post_date;
- }
-
- // The tricky bit!!
- // Using the parent ID of the current page as the
- // array index we set the curent page as a child of that page.
- // We can now start looping over the $page_tree array
- // with any ID which will output the page links from that ID downwards.
- if ( $page->post_parent != $page->ID)
- $page_tree[$page->post_parent]['children'][] = $page->ID;
- }
- // Output of the pages starting with child_of as the root ID.
- // child_of defaults to 0 if not supplied in the query.
- $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false);
- if ( $r['title_li'] )
- $output .= '</ul></li>';
+ if ( ! empty($pages) ) {
+ $output = "<select name='$name'>\n";
+ $output .= walk_page_dropdown_tree($pages, $depth, $r);
+ $output .= "</select>\n";
}
- $output = apply_filters('wp_list_pages', $output);
+ $output = apply_filters('wp_dropdown_pages', $output);
- if ( $r['echo'] )
+ if ( $echo )
echo $output;
- else
- return $output;
-}
+ return $output;
+}
-function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
- global $wp_query;
- $queried_obj = $wp_query->get_queried_object();
- $output = '';
+function wp_list_pages($args = '') {
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
- if ( $depth )
- $indent = str_repeat("\t", $depth);
- //$indent = join('', array_fill(0,$depth,"\t"));
+ $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_settings('date_format'),
+ 'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1);
+ $r = array_merge($defaults, $r);
- if ( !is_array($page_tree[$parent]['children']) )
- return false;
+ $output = '';
- foreach ( $page_tree[$parent]['children'] as $page_id ) {
- $cur_page = $page_tree[$page_id];
- $title = $cur_page['title'];
+ // Query pages.
+ $pages = get_pages($r);
- $css_class = 'page_item';
- if ( $page_id == $queried_obj->ID )
- $css_class .= ' current_page_item';
+ if ( !empty($pages) ) {
+ if ( $r['title_li'] )
+ $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
- $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>';
+ global $wp_query;
+ $current_page = $wp_query->get_queried_object_id();
+ $output .= walk_page_tree($pages, $r['depth'], $current_page, $r['show_date'], $r['date_format']);
- 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 ( $r['title_li'] )
+ $output .= '</ul></li>';
+ }
- if ( isset($cur_page['children']) && is_array($cur_page['children']) ) {
- $new_depth = $depth + 1;
+ $output = apply_filters('wp_list_pages', $output);
- if ( !$args['depth'] || $depth < ($args['depth']-1) ) {
- $output .= "$indent<ul>\n";
- $output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false);
- $output .= "$indent</ul>\n";
- }
- }
- $output .= "$indent</li>\n";
- }
- if ( $echo )
+ if ( $r['echo'] )
echo $output;
else
return $output;