PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.8.0
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.8.0
1.8.0 1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 All 27 releases
flywp / includes / StaticSite / Engine / Discovery / Pagination.php

Pagination.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.8.0, at includes/StaticSite/Engine/Discovery/Pagination.php

45 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\StaticSite\Engine\Discovery;
4
5 /**
6 * Pagination URLs of a list page.
7 *
8 * Pages come from the item count and posts_per_page. The URL format comes from the gateway (not a fixed "/page/N/").
9 *
10 * @since 1.8.0
11 */
12 class Pagination {
13
14 /**
15 * @param int $item_count Number of items in the list.
16 * @param int $per_page Items on one page.
17 *
18 * @return int Number of pages, 1 or more. posts_per_page 0 or less (for example -1) shows all items on one page.
19 */
20 public static function page_count( $item_count, $per_page ) {
21 if ( (int) $per_page <= 0 ) {
22 return 1;
23 }
24
25 return max( 1, (int) ceil( (int) $item_count / (int) $per_page ) );
26 }
27
28 /**
29 * URLs of page 2 and later pages.
30 *
31 * @param WordPressGateway $wp Gateway.
32 * @param string $base_url Page 1 URL.
33 * @param int $item_count Number of items in the list.
34 *
35 * @return \Generator<DiscoveredUrl>
36 */
37 public static function urls( WordPressGateway $wp, $base_url, $item_count ) {
38 $last = self::page_count( $item_count, $wp->option( 'posts_per_page' ) );
39
40 for ( $page = 2; $page <= $last; $page++ ) {
41 yield new DiscoveredUrl( $wp->paged_url( $base_url, $page ), 'pagination' );
42 }
43 }
44 }
45