[wp-hackers] wp_list_pages

Chris Waigl fz.serendipity at gmail.com
Fri Dec 10 20:36:04 UTC 2004


On Fri, 10 Dec 2004 19:05:18 +0100, Adi Sieker <ml at sieker.info> wrote:
> Hi,
> 
> attached is a preliminary version of wp_list_pages which supports
> hierarchies. The file if a diff created with cvs diff -U3 filename
> 
> It supports the following options:
> - child_of: Only select childern of the specified page ID. - default: 0
> - optiondates: display the date the page was created. - default: 0
> - modifieddate: if optiondates is set display the date the page was modified. - default: 0
> - date_format: use this date format instead of the one from the options. - default: ''
> - depth: only recurse this deep, if set to 0 display all levels. - default:0.
> _ sort_column: Sort output by this column - default: post_title
> - sort_order: specify sort order - default:ASC

Oops you're fast -- I only saw that you're working on this a few hours ago.

I'm still a very basic-level coder, but it happens that I slightly
rewrote the existing function, too. No hierarchies, but there are two
things I don't think you did: a) add a class "current" to the list
item of the current page (for menu styling) and remove the hyperlink
from that item and b) an option not to print but to return an array of
pages.

FYI, I'm copying my (much more basic) function below. Feel free to
disregard all this.

Chris

function cfw_list_pages($sort_column='title', $sort_order='asc',
$before='', $after='', $display= true ) {
// before and after not implemented
	global $wpdb, $wp_query;

	$page_obj = $wp_query->get_queried_object();
	$thispage = $page_obj->post_name;
	
	$pages = $wpdb->get_results("SELECT ID, post_title, post_name FROM
$wpdb->posts WHERE post_status = 'static' ORDER BY post_" .
$sort_column . " " . $sort_order);
		
	if ($display) {
		foreach ($pages as $page) {
     			$title = apply_filters('the_title', $page->post_title);

			echo '<li';
			if (is_page($page->post_name)) {
				echo ' class="current">'. $title ; 
			} else {
				echo '><a href="' . get_page_link($page->ID) . '" title="' .
htmlspecialchars($title) . '">' . $title . '</a>';
			}
			echo "</li>\n";
		}
	} else {
		return $pages;
	}
}
-- 

Chris Waigl
blog: http://serendipity.lascribe.net/ 
experiments: http://chrysalidesque.f2o.org



More information about the hackers mailing list