コード例 #1
0
ファイル: BlogTagSearch.php プロジェクト: janusnic/OctoberCMS
 /**
  * Load a page of posts
  */
 public function onLoadPage($page = false)
 {
     // Determine which page we're attempting to load
     $this->currentPage = $page ?: intval(post('page'));
     // Calculate the pagination variables
     $this->calculatePagination();
     // Query the tag with it's posts
     $this->tag = Tag::where('name', $this->property('tag'))->with(['posts' => function ($posts) {
         $posts->skip($this->resultsPerPage * ($this->currentPage - 1))->take($this->resultsPerPage);
     }])->first();
     // Count the posts being returned
     $this->postsOnPage = $this->tag ? count($this->tag->posts) : 0;
 }
コード例 #2
0
ファイル: BlogTagSearch.php プロジェクト: jiiis/ptn
 /**
  * Load a page of posts
  */
 public function onLoadPage($page = false)
 {
     // Determine which page we're attempting to load
     $this->currentPage = $page ?: intval(post('page'));
     // Calculate the pagination variables
     $this->calculatePagination();
     // Query the tag with it's posts
     $this->tag = Tag::where('name', $this->property('tag'))->with(['posts' => function ($posts) {
         $posts->skip($this->resultsPerPage * ($this->currentPage - 1))->take($this->resultsPerPage);
     }])->first();
     // Store the posts in a better container
     if (empty($this->tag)) {
         $this->posts = null;
         $this->postsOnPage = 0;
     } else {
         $this->posts = $this->tag->posts;
         $this->postsOnPage = count($this->posts);
         // Add a "url" helper attribute for linking to each post
         $this->posts->each(function ($post) {
             $post->setUrl($this->postPage, $this->controller);
             if ($post->categories->count()) {
                 $post->categories->each(function ($category) {
                     $category->setUrl($this->categoryPage, $this->controller);
                 });
             }
         });
     }
 }