page_rows

Definition:
function page_rows($pages, $pagenum = 1, $per_page = 20) {}

Parameters

  • unknown_type $pages
  • unknown_type $pagenum
  • unknown_type $per_page

Source code

function page_rows($pages, $pagenum = 1, $per_page = 20) {

	global $wpdb;



	$level = 0;



	if ( ! $pages ) {

		$pages = get_pages( array('sort_column' => 'menu_order') );



		if ( ! $pages )

			return false;

	}



	/*

	 * arrange pages into two parts: top level pages and children_pages

	 * children_pages is two dimensional array, eg.

	 * children_pages[10][] contains all sub-pages whose parent is 10.

	 * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations

	 * If searching, ignore hierarchy and treat everything as top level

	 */

	if ( empty($_GET['s']) ) {



		$top_level_pages = array();

		$children_pages = array();



		foreach ( $pages as $page ) {



			// catch and repair bad pages

			if ( $page->post_parent == $page->ID ) {

				$page->post_parent = 0;

				$wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));

				clean_page_cache( $page->ID );

			}



			if ( 0 == $page->post_parent )

				$top_level_pages[] = $page;

			else

				$children_pages[ $page->post_parent ][] = $page;

		}



		$pages = &$top_level_pages;

	}



	$count = 0;

	$start = ($pagenum - 1) * $per_page;

	$end = $start + $per_page;



	foreach ( $pages as $page ) {

		if ( $count >= $end )

			break;



		if ( $count >= $start )

			echo "\t" . display_page_row( $page, $level );



		$count++;



		if ( isset($children_pages) )

			_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );

	}



	// if it is the last pagenum and there are orphaned pages, display them with paging as well

	if ( isset($children_pages) && $count < $end ){

		foreach( $children_pages as $orphans ){

			foreach ( $orphans as $op ) {

				if ( $count >= $end )

					break;

				if ( $count >= $start )

					echo "\t" . display_page_row( $op, 0 );

				$count++;

			}

		}

	}

}

2471

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: