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

countByTag() public method

Return an array of the most $num recent posts, including URL and title
public countByTag ( integer $tag ) : integer
$tag integer
return integer
    public function countByTag(int $tag) : int
    {
        return (int) $this->db->cell('SELECT
                count(p.postid)
            FROM
                hull_blog_posts p
            LEFT JOIN
              hull_blog_post_tags t
              ON t.postid = p.postid
            WHERE
                p.status
                AND p.published <= current_timestamp
                AND t.tagid = ?', $tag);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * List all of the blog posts for a given tag
  *
  * @route blog/tag/{slug}/{page}
  * @param string $slug
  * @param string $page
  */
 public function listByTag(string $slug, string $page = '')
 {
     list($offset, $limit) = $this->getOffsetAndLimit($page);
     $tag = $this->blog->getTag($slug);
     $count = $this->blog->countByTag((int) $tag['tagid']);
     $blogRoll = $this->blog->listByTag((int) $tag['tagid'], $limit, $offset);
     $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 = $mathJAX || \strpos($blog['body'], '$$') !== false;
     }
     $args = ['blogroll' => $blogRoll, 'pageTitle' => \__('Blog Posts Tagged "%s"', 'default', Util::noHTML($tag['name'])), 'mathjax' => $mathJAX, 'pagination' => ['base' => \Airship\LensFunctions\cabin_url() . 'blog/tag/' . $slug, 'count' => $count, 'page' => (int) \ceil($offset / ($limit ?? 1)) + 1, 'per_page' => $limit]];
     $this->config('blog.cachelists') ? $this->stasis('blog/tag', $args) : $this->lens('blog/tag', $args);
 }