Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
@@ -15,13 +15,15 @@
|
||||
* @return string Returns the pagination numbers for the Query.
|
||||
*/
|
||||
function render_block_core_query_pagination_numbers( $attributes, $content, $block ) {
|
||||
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
|
||||
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
|
||||
$max_page = isset( $block->context['query']['pages'] ) ? (int) $block->context['query']['pages'] : 0;
|
||||
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
|
||||
$enhanced_pagination = isset( $block->context['enhancedPagination'] ) && $block->context['enhancedPagination'];
|
||||
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
|
||||
$max_page = isset( $block->context['query']['pages'] ) ? (int) $block->context['query']['pages'] : 0;
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes();
|
||||
$content = '';
|
||||
global $wp_query;
|
||||
$mid_size = isset( $block->attributes['midSize'] ) ? (int) $block->attributes['midSize'] : null;
|
||||
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
|
||||
// Take into account if we have set a bigger `max page`
|
||||
// than what the query has.
|
||||
@@ -30,7 +32,10 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo
|
||||
'prev_next' => false,
|
||||
'total' => $total,
|
||||
);
|
||||
$content = paginate_links( $paginate_args );
|
||||
if ( null !== $mid_size ) {
|
||||
$paginate_args['mid_size'] = $mid_size;
|
||||
}
|
||||
$content = paginate_links( $paginate_args );
|
||||
} else {
|
||||
$block_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) );
|
||||
// `paginate_links` works with the global $wp_query, so we have to
|
||||
@@ -45,6 +50,9 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo
|
||||
'total' => $total,
|
||||
'prev_next' => false,
|
||||
);
|
||||
if ( null !== $mid_size ) {
|
||||
$paginate_args['mid_size'] = $mid_size;
|
||||
}
|
||||
if ( 1 !== $page ) {
|
||||
/**
|
||||
* `paginate_links` doesn't use the provided `format` when the page is `1`.
|
||||
@@ -77,9 +85,24 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo
|
||||
wp_reset_postdata(); // Restore original Post Data.
|
||||
$wp_query = $prev_wp_query;
|
||||
}
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( $enhanced_pagination ) {
|
||||
$p = new WP_HTML_Tag_Processor( $content );
|
||||
while ( $p->next_tag(
|
||||
array(
|
||||
'tag_name' => 'a',
|
||||
'class_name' => 'page-numbers',
|
||||
)
|
||||
) ) {
|
||||
$p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
|
||||
}
|
||||
$content = $p->get_updated_html();
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<div %1$s>%2$s</div>',
|
||||
$wrapper_attributes,
|
||||
|
||||
Reference in New Issue
Block a user