How to hide one of the October Rainlab Blog categories? One of the categories should not be displayed in the Categories List on page. I want to use one hidden category only for filtering and display special posts on HomePage. Any ideas?
Asked
Active
Viewed 560 times
3 Answers
0
I am not sure what do you mean by "hide" here. but I guess you Don't want to Display it on Front-end (by Default)
You can extend Category model to do that.
if you have relative plugin / or / create your own plugin and in Plugin.php file define/override boot method and you can define something like this
use App;
use October\Rain\Database\Builder;
[...other code ...]
public function boot(){
\RainLab\Blog\Models\Category::extend(function($model) {
// App::runningInBackend() you can also use this one to make sure it will
// execute on frontend only
if(!App::runningInBackend()) {
$model::addGlobalScope('id', function(Builder $builder) {
$builder->where('id', '!=', 2);
});
}
});
}
Now, at the front-end side it will not show the categorie which is having id => 2
May be this can help you and If you need anything else please comment. For plugin related details you can check here : https://octobercms.com/docs/plugin/registration

Hardik Satasiya
- 9,547
- 3
- 22
- 40
-
How to add **multiple IDs**? – Elisseii Nov 08 '17 at 12:45
-
Done, I found a solution:) – Elisseii Nov 08 '17 at 17:10
-
This code hide the category, but also its posts on all pages of the site. If someone wants to hide a category on only one page, then just use the appropriate check. – Elisseii Dec 19 '17 at 14:53
0
Select multiple IDs of categories. Example.
use App;
use October\Rain\Database\Builder;
[...other code ...]
public function boot(){
\RainLab\Blog\Models\Category::extend(function($model) {
// App::runningInBackend() you can also use this one to make sure it will
// execute on frontend only
if(!App::runningInBackend()) {
$model::addGlobalScope('id', function(Builder $builder) {
$builder->where([
['id', '!=', 2],
['id', '!=', 3],
['id', '!=', 4]
]);
});
}
});
}
Now will not show the categories which is having id => 2,3,4

Elisseii
- 29
- 9
-
yes, now you have $builder, whatever conditions you like you can add them :) – Hardik Satasiya Nov 09 '17 at 06:57
0
A little shorter version with whereNotIn
eloquent method
$builder->whereNotIn('id', [22, 32, 44]);

Edgars Ozolins
- 298
- 5
- 11