Airship\Cabin\Hull\Blueprint\Blog::recentFullPosts PHP Method

recentFullPosts() public method

Return an array of the most $num recent posts, including URL and title
public recentFullPosts ( integer $num = 20, integer $offset ) : array
$num integer
$offset integer
return array
    public function recentFullPosts(int $num = 20, int $offset = 0) : array
    {
        $posts = $this->db->run('SELECT
                *
            FROM
                view_hull_blog_post
            WHERE
                status
                AND published <= current_timestamp
            ORDER BY published DESC
            OFFSET ' . $offset . '
            LIMIT ' . $num);
        if (empty($posts)) {
            return [];
        }
        foreach ($posts as $i => $post) {
            $posts[$i] = $this->postProcess($post);
        }
        return $posts;
    }

Usage Example

Example #1
0
 /**
  * The homepage for an Airship.
  *
  * @route /
  */
 public function index()
 {
     $this->blog = $this->blueprint('Blog');
     if (!\file_exists(ROOT . '/public/robots.txt')) {
         // Default robots.txt
         \file_put_contents(ROOT . '/public/robots.txt', "User-agent: *\nAllow: /");
     }
     $blogRoll = $this->blog->recentFullPosts((int) ($this->config('homepage.blog-posts') ?? 5));
     $mathJAX = false;
     foreach ($blogRoll as $i => $blog) {
         $blogRoll[$i] = $this->blog->getSnippet($blog);
         if (Binary::safeStrlen($blogRoll[$i]['snippet']) !== Binary::safeStrlen($blog['body'])) {
             $blogRoll[$i]['snippet'] = \rtrim($blogRoll[$i]['snippet'], "\n");
         }
         $mathJAX |= \strpos($blog['body'], '$$') !== false;
     }
     $args = ['blogposts' => $blogRoll];
     $this->config('blog.cachelists') ? $this->stasis('index', $args) : $this->lens('index', $args);
 }
All Usage Examples Of Airship\Cabin\Hull\Blueprint\Blog::recentFullPosts