【问题标题】:On Octobercms frontend sort blog menu items at Descending在 Octobercms 前端按降序排序博客菜单项
【发布时间】:2020-11-14 05:23:34
【问题描述】:

Octobercms 博客插件具有为 RainLab.Pages 插件注册菜单项的功能:

    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);
        }
    });
}

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

【问题讨论】:

    标签: octobercms octobercms-plugins octobercms-backend


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多