]> git.bts.cx Git - cx.git/blobdiff - cx/lib/posts.php
Better pagination support
[cx.git] / cx / lib / posts.php
index 7b1316643984a0ad2569831c7e820833df4a9874..b187c51c46c41f3a55b72b39a085d9792d77ab20 100644 (file)
@@ -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,