在Octobercms前端,在Descending对博客菜单项进行排序



Octobercms博客插件有一个为RainLab注册菜单项的功能。页面插件:

public function boot()
{
/*
* Register menu items for the RainLab.Pages plugin
*/
Event::listen('pages.menuitem.listTypes', function() {
return [
'blog-category'       => 'rainlab.blog::lang.menuitem.blog_category',
'all-blog-categories' => 'rainlab.blog::lang.menuitem.all_blog_categories',
'blog-post'           => 'rainlab.blog::lang.menuitem.blog_post',
'all-blog-posts'      => 'rainlab.blog::lang.menuitem.all_blog_posts',
'category-blog-posts' => 'rainlab.blog::lang.menuitem.category_blog_posts',
];
});
Event::listen('pages.menuitem.getTypeInfo', function($type) {
if ($type == 'blog-category' || $type == 'all-blog-categories') {
return Category::getMenuTypeInfo($type);
}
elseif ($type == 'blog-post' || $type == 'all-blog-posts' || $type == 'category-blog-posts') {
return Post::getMenuTypeInfo($type);
}
});
Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) {
if ($type == 'blog-category' || $type == 'all-blog-categories') {
return Category::resolveMenuItem($item, $url, $theme);
}
elseif ($type == 'blog-post' || $type == 'all-blog-posts' || $type == 'category-blog-posts') {
return Post::resolveMenuItem($item, $url, $theme);
}
});
}

例如,你可以在前端菜单中获得来自特定类别的所有帖子,作为菜单项。问题是,没有设置可以对帖子列表进行排序,也没有采用后端的顺序。因此,我试图找到一种方法来订购那些从分类帖子中生成的菜单项,但没有成功。

由于没有设置可以选择排序,也没有事件可以挂接来修改列表,因此唯一的选择是注册自己的menuItem类型来执行您想要的操作。通过模拟博客插件的功能,只需根据您的需要更改orderBy()查询过滤器,这应该相当容易。

最新更新