1 <?php
defined('IN_CMS') or die('No direct access allowed.');
4 Theme functions for posts
7 if(($posts = IoC
::resolve('posts')) === false) {
9 'status' => 'published',
12 'limit' => Config
::get('metadata.posts_per_page', 10),
13 'offset' => Input
::get('offset', 0)
15 $posts = Posts
::list_all($params);
16 IoC
::instance('posts', $posts, true);
18 $total_posts = Posts
::count(array('status' => 'published'));
19 IoC
::instance('total_posts', $total_posts, true);
22 return $posts->length() > 0;
26 if(has_posts() === false) {
30 $posts = IoC
::resolve('posts');
32 if($result = $posts->valid()) {
33 // register single post
34 IoC
::instance('article', $posts->current(), true);
43 function posts_next($text = 'Next', $default = '') {
44 $per_page = Config
::get('metadata.posts_per_page');
45 $offset = Input
::get('offset', 0);
46 $total = IoC
::resolve('total_posts');
48 $pages = floor($total / $per_page);
49 $page = $offset / $per_page;
52 return '<a href="' . current_url() . '?offset=' . ($offset +
$per_page) . '">' . $text . '</a>';
58 function posts_prev($text = 'Previous', $default = '') {
59 $per_page = Config
::get('metadata.posts_per_page');
60 $offset = Input
::get('offset', 0);
61 $total = IoC
::resolve('total_posts');
63 $pages = ceil($total / $per_page);
64 $page = $offset / $per_page;
67 return '<a href="' . current_url() . '?offset=' . ($offset - $per_page) . '">' . $text . '</a>';