diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 60099836..5aac28e4 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -406,10 +406,18 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe if (!empty($limit)) { if (isset($serendipity['GET']['page']) && ($serendipity['GET']['page'] > 1 || serendipity_db_bool($serendipity['archiveSortStable'])) && !strstr($limit, ',')) { - if (serendipity_db_bool($serendipity['archiveSortStable'])) { - $totalEntries = serendipity_getTotalEntries(); + + $totalEntries = serendipity_getTotalEntries(); + $totalPages = ceil($totalEntries / $limit); + + // Do not allow requesting a page that doesn't exist + // and do a fallback to the highest page number available + if ($serendipity['GET']['page'] > $totalPages) { + $serendipity['GET']['page'] = $totalPages; + } + + if (serendipity_db_bool($serendipity['archiveSortStable'])) { - $totalPages = ceil($totalEntries / $limit); if ($totalPages <= 0 ) { $totalPages = 1; }