使用OctoberCMS RainLab Blog获取不同类别的组合帖子

Pol*_*Zen 0 laravel octobercms octobercms-plugins

我在10月CMS使用Rain Lab Post.我使用blogPost组件没有问题,并从单个类别发布.例如,这是显示类别中最后5个帖子的部分内容

[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ slug }}"
postsPerPage = 5
noPostsMessage = "No news in this category"
sortOrder = "published_at desc"
categoryPage = 404
postPage = "singlePost"
==
<li> <a href="#">{{category.name}}</a>
    <ul class="drop-down full-width col-5 hover-expand">
        <li class="validation">
            <h2 class="mm-title">{{category.name}}</h2>
        </li>
        {% for post in posts %}
        <li>
            {% for image in post.featured_images|slice(0,1) %}
                <a href="{{ post.url }}"><img src="{{ image.path }}" alt=""></a>
            {% endfor %}
            <h3><a href="{{ post.url }}">{{post.title}}</a></h3>
        </li>
        {% endfor %}
    </ul>
</li>
Run Code Online (Sandbox Code Playgroud)

但现在,我正在主页上工作,想要显示所有类别的最后一篇文章.每类1个,5个类别,合并.

有人知道怎么做吗?

提前致谢

Pol*_*Zen 5

感谢Ahmed Essam的第一次接受,我在下一步解决了这个问题:

function onStart(){
   $categories = Db::table('rainlab_blog_categories')->get();
   foreach ($categories as $key=>$category){
      if($category->slug != 'uncategorized'){
         $first = \Rainlab\Blog\Models\Category::with('posts')->where('id',$category->id)->first();
         $data[] = $first->posts[0];
      }
   }
   $this['posts'] = $data;
}
Run Code Online (Sandbox Code Playgroud)

在模板中,我可以这样使用

{% for post in posts %}
    <li class="col-md-6 col-sm-6">
        <div id="container">

            {% for image in post.featured_images | slice(0,1) %}
               <div class="thumb"><img src="{{image.path}}" alt=""></div>
            {% endfor %}

            <div class="content">

                {% for category in post.categories %}
                    <div class="cat">{{category.name}</div>
                {% endfor %}

                <h3><a href="{{ post.url }}">{{ post.title )}}</a></h3>
            </div>
        </div>
    </li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)