pagination.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * A template partial to output pagination for the Twenty Twenty default theme.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Twenty
  9. * @since Twenty Twenty 1.0
  10. */
  11. /**
  12. * Translators:
  13. * This text contains HTML to allow the text to be shorter on small screens.
  14. * The text inside the span with the class nav-short will be hidden on small screens.
  15. */
  16. $prev_text = sprintf(
  17. '%s <span class="nav-prev-text">%s</span>',
  18. '<span aria-hidden="true">&larr;</span>',
  19. __( 'Newer <span class="nav-short">Posts</span>', 'twentytwenty' )
  20. );
  21. $next_text = sprintf(
  22. '<span class="nav-next-text">%s</span> %s',
  23. __( 'Older <span class="nav-short">Posts</span>', 'twentytwenty' ),
  24. '<span aria-hidden="true">&rarr;</span>'
  25. );
  26. $posts_pagination = get_the_posts_pagination(
  27. array(
  28. 'mid_size' => 1,
  29. 'prev_text' => $prev_text,
  30. 'next_text' => $next_text,
  31. )
  32. );
  33. // If we're not outputting the previous page link, prepend a placeholder with `visibility: hidden` to take its place.
  34. if ( strpos( $posts_pagination, 'prev page-numbers' ) === false ) {
  35. $posts_pagination = str_replace( '<div class="nav-links">', '<div class="nav-links"><span class="prev page-numbers placeholder" aria-hidden="true">' . $prev_text . '</span>', $posts_pagination );
  36. }
  37. // If we're not outputting the next page link, append a placeholder with `visibility: hidden` to take its place.
  38. if ( strpos( $posts_pagination, 'next page-numbers' ) === false ) {
  39. $posts_pagination = str_replace( '</div>', '<span class="next page-numbers placeholder" aria-hidden="true">' . $next_text . '</span></div>', $posts_pagination );
  40. }
  41. if ( $posts_pagination ) { ?>
  42. <div class="pagination-wrapper section-inner">
  43. <hr class="styled-separator pagination-separator is-style-wide" aria-hidden="true" />
  44. <?php echo $posts_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped during generation. ?>
  45. </div><!-- .pagination-wrapper -->
  46. <?php
  47. }