From bc96650b4c09cb3d44b3cd33607d3e7f363ad8fb Mon Sep 17 00:00:00 2001 From: jaquer Date: Wed, 26 Jan 2022 12:46:15 -0800 Subject: Improved pagination. Link for 'older/newer updates' pages only show if there's more pages to be shown in their corresponding directions. --- functions.php | 12 ++++++++++++ microblog.css | 1 - timeline.inc.php | 8 ++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 19325d1..5941ed8 100644 --- a/functions.php +++ b/functions.php @@ -62,6 +62,18 @@ function db_select_posts($from=NOW, $amount=10, $sort='desc', $page=1) { return (!empty($rows)) ? $rows : false; } +function db_posts_count() { + global $config; + global $db; + if(empty($db)) return false; + + $statement = $db->prepare('SELECT COUNT(*) AS posts_count FROM posts'); + $statement->execute(); + $row = $statement->fetch(PDO::FETCH_ASSOC); + + return (int) $row['posts_count']; +} + /* function that pings the official micro.blog endpoint for feed refreshes */ function ping_microblog() { global $config; diff --git a/microblog.css b/microblog.css index 0f46fdf..711cb67 100644 --- a/microblog.css +++ b/microblog.css @@ -71,7 +71,6 @@ nav li + li a { font-weight: bold; float: left; } -.timeline .pagination a.disabled { background-color: #b5b5af; } .timeline .pagination .next { float: right; } .wrap .post-timestamp { diff --git a/timeline.inc.php b/timeline.inc.php index c36b3bd..26b90bf 100644 --- a/timeline.inc.php +++ b/timeline.inc.php @@ -10,8 +10,8 @@ // pagination $current_page = (path(0) == 'page' && is_numeric(path(1))) ? (int) path(1) : 1; - $previous_page = ($current_page > 1) ? $current_page-1 : 1; - $next_page = $current_page + 1; + $posts_count = db_posts_count(); + $total_pages = ceil($posts_count / $config['posts_per_page']); // get posts $posts = db_select_posts(NOW, $config['posts_per_page'], 'desc', $current_page); @@ -49,8 +49,8 @@

No posts found.

-- cgit v1.2.3