From: Ben Sherratt Date: Sun, 17 Mar 2024 21:58:18 +0000 (+0000) Subject: Basic support for pagination X-Git-Url: https://git.bts.cx/cx.git/commitdiff_plain?ds=inline Basic support for pagination --- diff --git a/cx/cx.php b/cx/cx.php index a47714b..2c71761 100644 --- a/cx/cx.php +++ b/cx/cx.php @@ -66,6 +66,7 @@ function cx_route($path) { if (count($path_components) == 0) { $template = 'list'; + $template_variables['page_number'] = 0; } else if (count($path_components) >= 1 && $path_components[0] == 'feed') { header('Content-type: application/atom+xml;'); $template = 'atom'; @@ -162,6 +163,11 @@ function cx_route($path) { } } } + } else if (count($path_components) >= 2 && $path_components[0] == 'page') { // FIXME sometime, needs more flexibility... + $page_number = $path_components[1]; + + $template = 'list'; + $template_variables['page_number'] = $page_number; } else if (count($path_components) >= 3) { // FIXME sometime, needs more flexibility... $year = $path_components[0]; $month = $path_components[1]; diff --git a/cx/lib/posts.php b/cx/lib/posts.php index 988d00e..7b13166 100644 --- a/cx/lib/posts.php +++ b/cx/lib/posts.php @@ -127,7 +127,7 @@ function cx_posts_delete_post($post_id) { cx_db_exec($sql, $post_id); } -function cx_posts_get(int $limit = 0, bool $include_drafts = false) { +function cx_posts_get(int $limit = 0, int $offset = 0, bool $include_drafts = false) { $sql = 'SELECT post_id, post_slug, @@ -147,6 +147,10 @@ function cx_posts_get(int $limit = 0, bool $include_drafts = false) { if ($limit > 0) { $sql .= ' LIMIT ' . $limit; } + + if ($offset > 0) { + $sql .= ' OFFSET ' . $offset; + } $sql .= ';'; diff --git a/cx/lib/site.php b/cx/lib/site.php index 4a80b60..c705060 100644 --- a/cx/lib/site.php +++ b/cx/lib/site.php @@ -55,6 +55,10 @@ function cx_site_url() { return $details['site_url']; } +function cx_site_posts_per_page() { + return 5; +} + cx_setup_register(1, function() { cx_db_exec('CREATE TABLE sites ( site_id INTEGER PRIMARY KEY, diff --git a/cx/templates/public/list.php b/cx/templates/public/list.php index 3b4cee2..072cbb4 100644 --- a/cx/templates/public/list.php +++ b/cx/templates/public/list.php @@ -1,6 +1,7 @@
- + + date) . '/' . date('m', $post->date) . '/' . $post->slug; ?> + +

Next Posts