隐藏十月 Rainlab 博客类别之一?
Hide one of the October Rainlab Blog categories?
如何隐藏 October Rainlab 博客 类别之一?
其中一个类别不应显示在页面上的类别列表中。
我想使用一个隐藏类别仅用于过滤并在主页上显示特殊帖子。
有什么想法吗?
我不知道你说的 "hide" 是什么意思。
但我猜你不想在前端显示它(默认)
您可以扩展 Category 模型来做到这一点。
如果您有相关插件/或/创建您自己的插件并在Plugin.php文件define/overrideboot 方法,你可以定义这样的东西
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 => 2
的类别
这可能对您有所帮助,如果您需要其他任何信息,请发表评论。
有关插件相关的详细信息,您可以在此处查看:https://octobercms.com/docs/plugin/registration
Select 多个类别 ID。例子.
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]
]);
});
}
});
}
现在不会显示具有 id => 2,3,4
的类别
使用 whereNotIn
eloquent 方法
的更短版本
$builder->whereNotIn('id', [22, 32, 44]);
如何隐藏 October Rainlab 博客 类别之一? 其中一个类别不应显示在页面上的类别列表中。 我想使用一个隐藏类别仅用于过滤并在主页上显示特殊帖子。 有什么想法吗?
我不知道你说的 "hide" 是什么意思。 但我猜你不想在前端显示它(默认)
您可以扩展 Category 模型来做到这一点。
如果您有相关插件/或/创建您自己的插件并在Plugin.php文件define/overrideboot 方法,你可以定义这样的东西
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 => 2
的类别这可能对您有所帮助,如果您需要其他任何信息,请发表评论。 有关插件相关的详细信息,您可以在此处查看:https://octobercms.com/docs/plugin/registration
Select 多个类别 ID。例子.
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]
]);
});
}
});
}
现在不会显示具有 id => 2,3,4
的类别使用 whereNotIn
eloquent 方法
$builder->whereNotIn('id', [22, 32, 44]);