wpseek.com
A WordPress-centric search engine for devs and theme authors



render_block_core_page_list › WordPress Function

Sincen/a
Deprecatedn/a
render_block_core_page_list ( $attributes, $content, $block )
Parameters: (3)
  • (array) $attributes The block attributes.
    Required: Yes
  • (array) $content The saved content.
    Required: Yes
  • (array) $block The parsed block.
    Required: Yes
Returns:
  • (string) Returns the page list markup.
Defined at:
Codex:

Renders the `core/page-list` block on server.



Source

function render_block_core_page_list( $attributes, $content, $block ) {
	static $block_id = 0;
	$block_id++;

	// TODO: When https://core.trac.wordpress.org/ticket/39037 REST API support for multiple orderby values is resolved,
	// update 'sort_column' to 'menu_order, post_title'. Sorting by both menu_order and post_title ensures a stable sort.
	// Otherwise with pages that have the same menu_order value, we can see different ordering depending on how DB
	// queries are constructed internally. For example we might see a different order when a limit is set to <499
	// versus >= 500.
	$all_pages = get_pages(
		array(
			'sort_column' => 'menu_order',
			'order'       => 'asc',
		)
	);

	$top_level_pages = array();

	$pages_with_children = array();

	foreach ( (array) $all_pages as $page ) {
		if ( $page->post_parent ) {
			$pages_with_children[ $page->post_parent ][ $page->ID ] = array(
				'title' => $page->post_title,
				'link'  => get_permalink( $page->ID ),
			);
		} else {
			$top_level_pages[ $page->ID ] = array(
				'title' => $page->post_title,
				'link'  => get_permalink( $page->ID ),
			);

		}
	}

	$nested_pages = nest_pages( $top_level_pages, $pages_with_children );

	$wrapper_markup = '<ul %1$s>%2$s</ul>';

	$items_markup = render_nested_page_list( $nested_pages );

	$colors          = block_core_page_list_build_css_colors( $block->context );
	$font_sizes      = block_core_page_list_build_css_font_sizes( $block->context );
	$classes         = array_merge(
		$colors['css_classes'],
		$font_sizes['css_classes']
	);
	$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
	$css_classes     = trim( implode( ' ', $classes ) );

	if ( $block->context && $block->context['showSubmenuIcon'] ) {
		$css_classes .= ' show-submenu-icons';
	}

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => $css_classes,
			'style' => $style_attribute,
		)
	);

	return sprintf(
		$wrapper_markup,
		$wrapper_attributes,
		$items_markup
	);
}