actions.php
1 month ago
bulk-actions.php
3 years ago
empty-message.php
2 years ago
empty-search.php
2 years ago
module.php
3 years ago
pagination-list.php
5 months ago
pagination.php
6 years ago
summary.php
10 months ago
tracking-data-chart.php
5 months ago
tracking-data.php
6 years ago
pagination-list.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Displays element to paginate modules in the listing page. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since 4.0.0 |
| 7 | */ |
| 8 | |
| 9 | if ( $total <= $entries_per_page ) { |
| 10 | return; |
| 11 | } |
| 12 | // don't use filter_input() here, because of see Hustle_Module_Admin::maybe_remove_paged function. |
| 13 | $paged = ! empty( $_GET['paged'] ) ? (int) $_GET['paged'] : 1; // phpcs:ignore |
| 14 | $args = array(); |
| 15 | if ( ! empty( $section ) ) { |
| 16 | $args['section'] = $section; |
| 17 | } |
| 18 | $base_url = add_query_arg( $args, remove_query_arg( 'paged' ) ); |
| 19 | $max = (int) ceil( $total / $entries_per_page ); |
| 20 | $short_pagination = 5 > $max; |
| 21 | ?> |
| 22 | <ul class="sui-pagination"> |
| 23 | <?php |
| 24 | /** |
| 25 | * Conditions: |
| 26 | * 1. Show this button if there are 5 pages or more. |
| 27 | * 2. Hide this button if first page is current page. |
| 28 | */ |
| 29 | if ( ! $short_pagination ) { |
| 30 | /** |
| 31 | * ELEMENT: Skip to first page |
| 32 | */ |
| 33 | ?> |
| 34 | <li class="sui-pagination--start"> |
| 35 | <a href="<?php echo esc_url( $base_url ); ?>" <?php disabled( $paged <= 1 ); ?>> |
| 36 | <span class="sui-icon-arrow-skip-start" aria-hidden="true"></span> |
| 37 | <span class="sui-screen-reader-text"><?php esc_html_e( 'Go to first page', 'hustle' ); ?></span> |
| 38 | </a> |
| 39 | </li> |
| 40 | |
| 41 | <?php |
| 42 | /** |
| 43 | * ELEMENT: Go to previous page |
| 44 | */ |
| 45 | $u = add_query_arg( 'paged', $paged - 1, $base_url ); |
| 46 | ?> |
| 47 | <li class="sui-pagination--next"> |
| 48 | <a href="<?php echo esc_url( $u ); ?>" <?php disabled( $paged <= 1 ); ?>> |
| 49 | <span class="sui-icon-chevron-left" aria-hidden="true"></span> |
| 50 | <span class="sui-screen-reader-text"><?php esc_html_e( 'Go to previous page', 'hustle' ); ?></span> |
| 51 | </a> |
| 52 | </li> |
| 53 | <?php |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * ELEMENT: List of pages |
| 58 | * |
| 59 | * 1. Use "sui-active" class to determine current page. |
| 60 | */ |
| 61 | $i = 1; |
| 62 | do { |
| 63 | if ( 1 < $i ) { |
| 64 | $u = add_query_arg( 'paged', $i, $base_url ); |
| 65 | } else { |
| 66 | $u = $base_url; |
| 67 | } |
| 68 | if ( |
| 69 | ! $short_pagination && |
| 70 | ( |
| 71 | ( $paged - 2 === $i && 1 !== $i ) || |
| 72 | ( $paged + 2 === $i && $i !== $max ) |
| 73 | ) |
| 74 | ) { |
| 75 | printf( |
| 76 | '<li><a href="%s"> ... </a></li>', |
| 77 | esc_url( $u ) |
| 78 | ); |
| 79 | } elseif ( |
| 80 | $short_pagination || |
| 81 | in_array( $i, range( $paged - 2, $paged + 2 ), true ) |
| 82 | ) { |
| 83 | printf( |
| 84 | '<li><a class="%s" href="%s">%d</a></li>', |
| 85 | esc_attr( $paged === $i ? 'sui-active' : '' ), |
| 86 | esc_url( $u ), |
| 87 | esc_html( $i ) |
| 88 | ); |
| 89 | } |
| 90 | ++$i; |
| 91 | } while ( $i <= $max ); |
| 92 | |
| 93 | /** |
| 94 | * Conditions: |
| 95 | * 1. Show this button if there are 5 pages or more. |
| 96 | * 2. Hide this button if last page is current page. |
| 97 | */ |
| 98 | if ( ! $short_pagination ) { |
| 99 | /** |
| 100 | * ELEMENT: Go to next page |
| 101 | */ |
| 102 | $u = add_query_arg( 'paged', $paged + 1, $base_url ); |
| 103 | ?> |
| 104 | <li class="sui-pagination--next"> |
| 105 | <a href="<?php echo esc_url( $u ); ?>" <?php disabled( $paged >= $max ); ?>> |
| 106 | <span class="sui-icon-chevron-right" aria-hidden="true"></span> |
| 107 | <span class="sui-screen-reader-text"><?php esc_html_e( 'Go to next page', 'hustle' ); ?></span> |
| 108 | </a> |
| 109 | </li> |
| 110 | <?php |
| 111 | |
| 112 | /** |
| 113 | * ELEMENT: Skip to last page |
| 114 | */ |
| 115 | $u = add_query_arg( 'paged', $max, $base_url ); |
| 116 | ?> |
| 117 | <li class="sui-pagination--end"> |
| 118 | <a href="<?php echo esc_url( $u ); ?>" <?php disabled( $paged >= $max ); ?>> |
| 119 | <span class="sui-icon-arrow-skip-end" aria-hidden="true"></span> |
| 120 | <span class="sui-screen-reader-text"><?php esc_html_e( 'Go to last page', 'hustle' ); ?></span> |
| 121 | </a> |
| 122 | </li> |
| 123 | <?php |
| 124 | } |
| 125 | ?> |
| 126 | </ul> |
| 127 |