administration notes:
Hacked wp-includes/post.php
<?php
/**
* get_page_children() - Retrieve child pages
*
* {@internal Missing Long Description}}
*
* @package WordPress
* @subpackage Post
* @since 1.5.1
*
* @param int $page_id page ID
* @param array $pages list of pages
* @return array {@internal Missing Description}}
*/
function &get_page_children($page_id, $pages, $depth = 0) {
$page_list = array();
foreach ( $pages as $page ) {
if ( $page->post_parent == $page_id ) {
$page_list[] = $page;
if($depth<=0||$depth>1)
if ( $children = get_page_children($page->ID, $pages, $depth-1 ) )
$page_list = array_merge($page_list, $children);
}
}
return $page_list;
}
/**
* get_pages() - Retrieve a list of pages
*
* {@internal Missing Long Description}}
*
* @package WordPress
* @subpackage Post
* @since 1.5
* @uses $wpdb
*
* @param mixed $args Optional. Array or string of options
* @return array List of pages matching defaults or $args
*/
function &get_pages($args = '') {
global $wpdb;
$defaults = array(
'child_of' => 0, 'sort_order' => 'ASC',
'sort_column' => 'post_title', 'hierarchical' => 1,
'exclude' => '', 'include' => '',
'meta_key' => '', 'meta_value' => '',
'authors' => '', 'depth' => 0
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_pages', 'posts' ) )
if ( isset( $cache[ $key ] ) )
return apply_filters('get_pages', $cache[ $key ], $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 = '';
$hierarchical = false;
$incpages = preg_split('/[\s,]+/',$include);
if ( count($incpages) ) {
foreach ( $incpages as $incpage ) {
if (empty($inclusions))
$inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
else
$inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
}
}
}
if (!empty($inclusions))
$inclusions .= ')';
$exclusions = '';
if ( !empty($exclude) ) {
$expages = preg_split('/[\s,]+/',$exclude);
if ( count($expages) ) {
foreach ( $expages as $expage ) {
if (empty($exclusions))
$exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
else
$exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
}
}
}
if (!empty($exclusions))
$exclusions .= ')';
$author_query = '';
if (!empty($authors)) {
$post_authors = preg_split('/[\s,]+/',$authors);
if ( count($post_authors) ) {
foreach ( $post_authors as $post_author ) {
//Do we have an author id or an author login?
if ( 0 == intval($post_author) ) {
$post_author = get_userdatabylogin($post_author);
if ( empty($post_author) )
continue;
if ( empty($post_author->ID) )
continue;
$post_author = $post_author->ID;
}
if ( '' == $author_query )
$author_query = $wpdb->prepare(' post_author = %d ', $post_author);
else
$author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
}
if ( '' != $author_query )
$author_query = " AND ($author_query)";
}
}
$join = '';
$where = "$exclusions $inclusions ";
if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
$join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
// meta_key and met_value might be slashed
$meta_key = stripslashes($meta_key);
$meta_value = stripslashes($meta_value);
if ( ! empty( $meta_key ) )
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
if ( ! empty( $meta_value ) )
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
}
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
$query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;
$pages = $wpdb->get_results($query);
if ( empty($pages) )
return apply_filters('get_pages', array(), $r);
// Update cache.
update_page_cache($pages);
if ( $child_of || $hierarchical )
$pages = & get_page_children($child_of, $pages, $depth);
$cache[ $key ] = $pages;
wp_cache_set( 'get_pages', $cache, 'posts' );
$pages = apply_filters('get_pages', $pages, $r);
return $pages;
}
?>
This adds depth limiting to get_pages().
Note, Wordpress does not assign an ID to the top-level page, therefore it is not possible to request only the top-level pages. It just happens passing the argument hierarchical=1 (a boolean flag) has the side effect of procuring the top-level pages while the child_of argument is 0 (which normally disables parent based pruning -- and conveniently the parent ID you'll end up with for top-level pages)
It's worth noting there is no reason to presume this behavior will not change in future version of Wordpress. For now however hierarchical is equivalent to passing a non-zero child_of, so it is safe to combine the two this way.
This hack is used to generate an array of sibling pages from which the "prev" and "next" page flippers atop each page can be practically retrieved. « Last Edit: November 30, 2008, 08:26:30 PM by yksehtniycul »
マィカェル アルケヂア
word to the wise -- nice people are not always good; and good people are not always nice -- think on it.