From 2330cd1ae04b2eddcbefb83c4a0923f3a59959b9 Mon Sep 17 00:00:00 2001 From: merdan Date: Thu, 17 Jun 2021 15:32:19 +0500 Subject: [PATCH] featured --- plugins/rainlab/blog/components/Posts.php | 7 +++++-- plugins/rainlab/blog/models/Post.php | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/rainlab/blog/components/Posts.php b/plugins/rainlab/blog/components/Posts.php index 85ff2f953..82fddac57 100644 --- a/plugins/rainlab/blog/components/Posts.php +++ b/plugins/rainlab/blog/components/Posts.php @@ -88,7 +88,8 @@ class Posts extends ComponentBase 'featured' => [ 'title' => 'Featured posts', 'description' => 'Filter featured posts', - 'type' => 'checkbox', + 'type' => 'dropdown', + 'options' => ['yes' => 'Yes', 'not' => 'Not'] ], 'postsPerPage' => [ @@ -208,11 +209,13 @@ class Posts extends ComponentBase */ $isPublished = !$this->checkEditor(); + $featured = $this->property('featured') ? $this->property('featured')=='yes':null; + $posts = BlogPost::with(['categories'])->listFrontEnd([ 'page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage'), - 'featured' => $this->property('featured'), + 'featured' => $featured, 'search' => trim(input('q')), 'category' => $category, 'date' => input('date'), diff --git a/plugins/rainlab/blog/models/Post.php b/plugins/rainlab/blog/models/Post.php index ffad5e2fd..54e6bfb0c 100644 --- a/plugins/rainlab/blog/models/Post.php +++ b/plugins/rainlab/blog/models/Post.php @@ -282,8 +282,8 @@ class Post extends Model $query->isPublished(); } - if($featured){ - $query-> where('featured',1); + if(isset($featured)){ + $query-> where('featured',$featured); } $date = trim($date); @@ -399,7 +399,7 @@ class Post extends Model $q->whereIn('id', $categories); }); } - + public function scopeFilterLocale($query, array $types) { foreach ($types as $type) { switch ($type) { @@ -411,8 +411,8 @@ class Post extends Model break; } } - - + + } //