0

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?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Elisseii
  • 29
  • 9

3 Answers3

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
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
0

A little shorter version with whereNotIn eloquent method

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

Edgars Ozolins
  • 298
  • 5
  • 11