WP_Posts_List_Table::_page_rows()privateWP 3.1.0

Displays the nested hierarchy of sub-pages together with paging support, based on a top level page ID.

Method of the class: WP_Posts_List_Table{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->_page_rows( $children_pages, $count, $parent_page, $level, $pagenum, $per_page, $to_display );
$children_pages(array) (required) (passed by reference — &)
-
$count(int) (required) (passed by reference — &)
-
$parent_page(int) (required)
-
$level(int) (required)
-
$pagenum(int) (required)
-
$per_page(int) (required)
-
$to_display(array) (required) (passed by reference — &)
List of pages to be displayed. Passed by reference.

Changelog

Since 3.1.0 Introduced.
Since 3.1.0 (Standalone function exists since 2.6.0)
Since 4.2.0 Added the $to_display parameter.

WP_Posts_List_Table::_page_rows() code WP 6.6.2

private function _page_rows( &$children_pages, &$count, $parent_page, $level, $pagenum, $per_page, &$to_display ) {
	if ( ! isset( $children_pages[ $parent_page ] ) ) {
		return;
	}

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

	foreach ( $children_pages[ $parent_page ] as $page ) {
		if ( $count >= $end ) {
			break;
		}

		// If the page starts in a subtree, print the parents.
		if ( $count === $start && $page->post_parent > 0 ) {
			$my_parents = array();
			$my_parent  = $page->post_parent;

			while ( $my_parent ) {
				// Get the ID from the list or the attribute if my_parent is an object.
				$parent_id = $my_parent;

				if ( is_object( $my_parent ) ) {
					$parent_id = $my_parent->ID;
				}

				$my_parent    = get_post( $parent_id );
				$my_parents[] = $my_parent;

				if ( ! $my_parent->post_parent ) {
					break;
				}

				$my_parent = $my_parent->post_parent;
			}

			$num_parents = count( $my_parents );

			while ( $my_parent = array_pop( $my_parents ) ) {
				$to_display[ $my_parent->ID ] = $level - $num_parents;
				--$num_parents;
			}
		}

		if ( $count >= $start ) {
			$to_display[ $page->ID ] = $level;
		}

		++$count;

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

	unset( $children_pages[ $parent_page ] ); // Required in order to keep track of orphans.
}