get_query_pagination_arrow()WP 5.9.0

Helper function that returns the proper pagination arrow HTML for QueryPaginationNext and QueryPaginationPrevious blocks based on the provided paginationArrow from QueryPagination context.

It's used in QueryPaginationNext and QueryPaginationPrevious blocks.

No Hooks.

Return

String|null. The pagination arrow HTML or null if there is none.

Usage

get_query_pagination_arrow( $block, $is_next );
$block(WP_Block) (required)
Block instance.
$is_next(true|false) (required)
Flag for handling next/previous blocks.

Changelog

Since 5.9.0 Introduced.

Code of get_query_pagination_arrow() WP 6.0

function get_query_pagination_arrow( $block, $is_next ) {
	$arrow_map = array(
		'none'    => '',
		'arrow'   => array(
			'next'     => '→',
			'previous' => '←',
		),
		'chevron' => array(
			'next'     => '»',
			'previous' => '«',
		),
	);
	if ( ! empty( $block->context['paginationArrow'] ) && array_key_exists( $block->context['paginationArrow'], $arrow_map ) && ! empty( $arrow_map[ $block->context['paginationArrow'] ] ) ) {
		$pagination_type = $is_next ? 'next' : 'previous';
		$arrow_attribute = $block->context['paginationArrow'];
		$arrow           = $arrow_map[ $block->context['paginationArrow'] ][ $pagination_type ];
		$arrow_classes   = "wp-block-query-pagination-$pagination_type-arrow is-arrow-$arrow_attribute";
		return "<span class='$arrow_classes'>$arrow</span>";
	}
	return null;
}