From: Ben Sherratt Date: Fri, 3 Jul 2026 08:01:03 +0000 (+0100) Subject: Better pagination support X-Git-Url: https://git.bts.cx/cx.git/commitdiff_plain/cac9928099ba10ab8a7d5ca4005dd78ff11b5ce3?ds=sidebyside Better pagination support --- diff --git a/cx/lib/images.php b/cx/lib/images.php index dbe55bf..ea29f74 100644 --- a/cx/lib/images.php +++ b/cx/lib/images.php @@ -95,5 +95,8 @@ cx_setup_register(1, function() { FOREIGN KEY(image_site_id) REFERENCES sites(site_id) );'); - mkdir(cx_user_data_path('images'), recursive: true); + $image_dir = cx_user_data_path('images'); + if (is_dir($image_dir) == false) { + mkdir($image_dir, recursive: true); + } }); diff --git a/cx/lib/posts.php b/cx/lib/posts.php index 7b13166..b187c51 100644 --- a/cx/lib/posts.php +++ b/cx/lib/posts.php @@ -160,6 +160,26 @@ function cx_posts_get(int $limit = 0, int $offset = 0, bool $include_drafts = fa } } +function cx_posts_count(bool $include_drafts = false) { + $sql = 'SELECT + COUNT(post_id) AS _count + FROM posts + WHERE post_is_page == FALSE'; + + if ($include_drafts == false) { + $sql .= ' AND post_is_draft == FALSE'; + } + + $sql .= ';'; + + + foreach (cx_db_query($sql) as $count_details) { + return $count_details['_count']; + } + + return 0; +} + function cx_posts_find_post($post_id) { $sql = 'SELECT post_id, diff --git a/cx/lib/url.php b/cx/lib/url.php index 1ace539..0bcef4c 100644 --- a/cx/lib/url.php +++ b/cx/lib/url.php @@ -13,3 +13,12 @@ function cx_url_admin($path) { function cx_url_site($path) { return cx_site_url() . cx_url($path); } + +function cx_url_page($number, $delta = 0) { + $next_number = $number + $delta; + if ($next_number <= 0) { + return cx_url_site('/'); + } else { + return cx_url_site('/page/' . $next_number ); + } +} diff --git a/cx/templates/public/base.php b/cx/templates/public/base.php index 927c09b..8629d34 100644 --- a/cx/templates/public/base.php +++ b/cx/templates/public/base.php @@ -15,9 +15,15 @@ + + + + + + + - hero_image)): ?> @@ -31,10 +37,6 @@ - - - */ ?> - diff --git a/cx/templates/public/list.php b/cx/templates/public/list.php index 072cbb4..0f02a71 100644 --- a/cx/templates/public/list.php +++ b/cx/templates/public/list.php @@ -15,5 +15,9 @@ -

Next Posts

+

+ + Older Posts + 0): ?>Newer Posts +

diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..ea851b8 --- /dev/null +++ b/setup.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +mkdir db +mkdir public/data +mkdir public/data/images + +cp setup.template.php setup.php + +echo "Now edit setup.php with your site details!"