]> git.bts.cx Git - cx.git/blobdiff - cx/lib/posts.php
Better pagination support
[cx.git] / cx / lib / posts.php
index 988d00eb008c457b873b67876d33f581213b9bba..b187c51c46c41f3a55b72b39a085d9792d77ab20 100644 (file)
@@ -127,7 +127,7 @@ function cx_posts_delete_post($post_id) {
        cx_db_exec($sql, $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,
        $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 ($limit > 0) {
                $sql .= ' LIMIT ' . $limit;
        }
+       
+       if ($offset > 0) {
+               $sql .= ' OFFSET ' . $offset;
+       }
 
        $sql .= ';';
 
 
        $sql .= ';';
 
@@ -156,6 +160,26 @@ function cx_posts_get(int $limit = 0, bool $include_drafts = false) {
        }
 }
 
        }
 }
 
+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,
 function cx_posts_find_post($post_id) {
        $sql = 'SELECT
                post_id,