0
votes

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?

3

3 Answers

0
votes

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

0
votes

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

0
votes

A little shorter version with whereNotIn eloquent method

$builder->whereNotIn('id', [22, 32, 44]);