diff --git a/theme/template-parts/blocks/query-pagination-first.php b/theme/template-parts/blocks/query-pagination-first.php index 5ed55cd1e..9bc2d4aa6 100644 --- a/theme/template-parts/blocks/query-pagination-first.php +++ b/theme/template-parts/blocks/query-pagination-first.php @@ -30,47 +30,41 @@ $label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label; $content = ''; $url = ''; -$wrapper_attributes = str_replace( 'class="', 'class="mdc-ripple-surface ', $wrapper_attributes ); // Check if the pagination is for Query that inherits the global context // and handle appropriately. if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) { - $url = get_pagenum_link( 1 ); -} elseif ( 1 !== $page_number ) { + global $wp_query; + $url = get_pagenum_link( 1 ); + $query_page_number = (int) get_query_var( 'paged' ); + $page_number = $query_page_number > 0 ? $query_page_number : $page_number; +} else { $url = add_query_arg( $page_key, 1 ); } +$is_disabled = 1 === $page_number; if ( ! empty( $url ) ) : - ob_start(); + $screen_reader = sprintf( + /* translators: available page description. */ + esc_html__( '%s page', 'material-design-google' ), + esc_html( $label ) + ); + $inner_content = sprintf( + ' + %s', + $screen_reader + ); + $inner_content_with_anchor = $is_disabled ? $inner_content : sprintf( + '%s', + esc_url( $url ), + $inner_content + ); + $content = sprintf( + '
  • %s
  • ', + $wrapper_attributes, + $inner_content_with_anchor + ); ?> -
  • - - - > - - - - - -
  • context['query']['inherit'] ) && $block->context['query']['inherit'] ) { // Take into account if we have set a bigger `max page` // than what the query has. global $wp_query; - $url = get_pagenum_link( $wp_query->max_num_pages ); + $max_page = $wp_query->max_num_pages; + $url = get_pagenum_link( $max_page ); + $current_page_num = get_query_var( 'paged' ); + $is_disabled = (int) $current_page_num === (int) $max_page; } elseif ( ! $max_page || $max_page > $page_number ) { $custom_query = new WP_Query( build_query_vars_from_query_block( $block, $page_number ) ); $custom_query_max_pages = (int) $custom_query->max_num_pages; - $wrapper_attributes = str_replace( 'class="', 'class="mdc-ripple-surface ', $wrapper_attributes ); - - if ( $custom_query_max_pages && $custom_query_max_pages !== $page_number ) : - $url = add_query_arg( $page_key, $custom_query_max_pages ); - endif; + $is_disabled = $custom_query_max_pages === $page_number; + $url = add_query_arg( $page_key, $custom_query_max_pages ); wp_reset_postdata(); // Restore original Post Data. } if ( ! empty( $url ) ) : - ob_start(); + $screen_reader = sprintf( + /* translators: available page description. */ + esc_html__( '%s page', 'material-design-google' ), + esc_html( $label ) + ); + $inner_content = sprintf( + ' + %s', + $screen_reader + ); + $inner_content_with_anchor = $is_disabled ? $inner_content : sprintf( + '%s', + esc_url( $url ), + $inner_content + ); + $content = sprintf( + '
  • %s
  • ', + $wrapper_attributes, + $inner_content_with_anchor + ); ?> -
  • - - - > - - - - - -
  • context['query']['inherit'] ) && $block->context['query']['inherit'] ) { @@ -42,49 +42,44 @@ if ( $max_page > $wp_query->max_num_pages ) { $max_page = $wp_query->max_num_pages; } - - $url = next_posts( $max_page, false ); + $max_page = $wp_query->max_num_pages; + $url = get_pagenum_link( $max_page ); + $current_page_num = get_query_var( 'paged' ); + $is_disabled = (int) $current_page_num === (int) $max_page; + $url = next_posts( $max_page, false ); + // Force in loop to show disabled state, as next_posts returns empty when on last page. + $url = $url ? $url : '#'; } elseif ( ! $max_page || $max_page > $page_number ) { $custom_query = new WP_Query( build_query_vars_from_query_block( $block, $page_number ) ); $custom_query_max_pages = (int) $custom_query->max_num_pages; - - if ( $custom_query_max_pages && $custom_query_max_pages !== $page_number ) : - $url = add_query_arg( $page_key, $page_number + 1 ); - endif; + $is_disabled = $custom_query_max_pages === $page_number; + // In case of disabled - url won't be used. + $url = add_query_arg( $page_key, $page_number + 1 ); wp_reset_postdata(); // Restore original Post Data. } if ( ! empty( $url ) ) : - ob_start(); + $screen_reader = sprintf( + /* translators: available page description. */ + esc_html__( '%s page', 'material-design-google' ), + esc_html( $label ) + ); + $inner_content = sprintf( + ' + %s', + $screen_reader + ); + $inner_content_with_anchor = $is_disabled ? $inner_content : sprintf( + '%s', + esc_url( $url ), + $inner_content + ); + $content = sprintf( + '
  • %s
  • ', + $wrapper_attributes, + $inner_content_with_anchor + ); ?> -
  • - - - > - - - - - -
  • context['query']['inherit'] ) && $block->context['query']['inherit'] ) { + global $wp_query; $url = previous_posts( false ); -} elseif ( 1 !== $page_number ) { + // Force in loop to show disabled state, as previous_posts returns empty when on first page. + $url = $url ? $url : '#'; + $query_page_number = (int) get_query_var( 'paged' ); + $page_number = $query_page_number > 0 ? $query_page_number : $page_number; +} else { $url = add_query_arg( $page_key, $page_number - 1 ); } +$is_disabled = 1 === $page_number; + if ( ! empty( $url ) ) : - ob_start(); + $screen_reader = sprintf( + /* translators: available page description. */ + esc_html__( '%s page', 'material-design-google' ), + esc_html( $label ) + ); + $inner_content = sprintf( + ' + %s', + $screen_reader + ); + $inner_content_with_anchor = $is_disabled ? $inner_content : sprintf( + '%s', + esc_url( $url ), + $inner_content + ); + $content = sprintf( + '
  • %s
  • ', + $wrapper_attributes, + $inner_content_with_anchor + ); ?> -
  • - - - > - - - - - -