diff options
-rw-r--r-- | functions.php | 12 | ||||
-rw-r--r-- | microblog.css | 1 | ||||
-rw-r--r-- | 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 @@ <p>No posts found.</p> <?php endif; ?> <div class="pagination"> - <a href="<?= $config['url'] ?>/page/<?= $previous_page ?>" class="previous<?= ($current_page == 1) ? ' disabled': '' ?>">newer updates</a> - <a href="<?= $config['url'] ?>/page/<?= $next_page ?>" class="next">older updates</a> + <?php if ($current_page > 1): ?><a href="<?= $config['url'] ?>/page/<?= $current_page - 1 ?>" class="previous">newer updates</a><?php endif; ?> + <?php if ($current_page < $total_pages): ?><a href="<?= $config['url'] ?>/page/<?= $current_page + 1 ?>" class="next">older updates</a><?php endif; ?> </div> </div> </body> |