public static function theme_page_selector($theme, $rr_name = null, $settings = array()) { // We can't detect proper pagination if $theme->posts isn't a Posts object, // so if it's not, bail. if (!$theme->posts instanceof Posts) { return ''; } $current = $theme->page; if (isset($theme->posts->get_param_cache['nolimit'])) { return; } $items_per_page = isset($theme->posts->get_param_cache['limit']) ? $theme->posts->get_param_cache['limit'] : Options::get('pagination'); $total = Utils::archive_pages($theme->posts->count_all(), $items_per_page); // Make sure the current page is valid if ($current > $total) { $current = $total; } else { if ($current < 1) { $current = 1; } } // Number of pages to display on each side of the current page. $leftSide = isset($settings['leftSide']) ? $settings['leftSide'] : 1; $rightSide = isset($settings['rightSide']) ? $settings['rightSide'] : 1; // Add the page '1'. $pages[] = 1; // Add the pages to display on each side of the current page, based on $leftSide and $rightSide. for ($i = max($current - $leftSide, 2); $i < $total && $i <= $current + $rightSide; $i++) { $pages[] = $i; } // Add the last page if there is more than one page. if ($total > 1) { $pages[] = (int) $total; } // Sort the array by natural order. natsort($pages); // This variable is used to know the last page processed by the foreach(). $prevpage = 0; // Create the output variable. $out = ''; if (1 === count($pages) && isset($settings['hideIfSinglePage']) && $settings['hideIfSinglePage'] === true) { return ''; } foreach ($pages as $page) { $settings['page'] = $page; // Add ... if the gap between the previous page is higher than 1. if ($page - $prevpage > 1) { $out .= ' <span class="sep">…</span>'; } // Wrap the current page number with square brackets. $caption = $page == $current ? $current : $page; // Build the URL using the supplied $settings and the found RewriteRules arguments. $url = URL::get($rr_name, $settings, false); // Build the HTML link. $out .= ' <a href="' . $url . '" ' . ($page == $current ? 'class="current-page"' : '') . '>' . $caption . '</a>'; $prevpage = $page; } // Run the result through filters so plugins may overwrite it $out = Plugins::filter('page_selector', $out, $pages, $rr_name); return $out; }