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';
}
}
}
+ } 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];
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,
if ($limit > 0) {
$sql .= ' LIMIT ' . $limit;
}
+
+ if ($offset > 0) {
+ $sql .= ' OFFSET ' . $offset;
+ }
$sql .= ';';
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,
<?php cx_template_base('base'); ?>
<main>
-<?php foreach (cx_posts_get() as $post): ?>
+<?php $posts_per_page = cx_site_posts_per_page(); ?>
+<?php foreach (cx_posts_get(limit: $posts_per_page, offset: $page_number * cx_site_posts_per_page()) as $post): ?>
<?php $post_permalink = '/' . date('Y', $post->date) . '/' . date('m', $post->date) . '/' . $post->slug; ?>
<article>
<h1><a href="<?= cx_url($post_permalink) ?>"><?= $post->title ?></a></h1>
<?php endif; ?>
</article>
<?php endforeach; ?>
+
+ <p><a href="<?= cx_url('/page/' . ($page_number + 1) . '/') ?>">Next Posts</a></p>
</main>