Search code examples
phplaravelblogsoctobercms

OctoberCMS - Rainlabs Blog plugin - foreach category display blog posts


Hello I want to have multiple categories on one page (as a preview). Example:

Category 1 
POST1, POST2...

Category 2 
POST1, POST2... 

Category 3 
POST1, POST2...
...

There can be many categories, so I want to loop through them and then displaying posts depending on actual category.

My blog component look like this:

[blogPosts categoriesPreview]
pageNumber = "{{ page }}"
categoryFilter = "top-recipes"
postsPerPage = 4
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "recipes-category"
postPage = "recipes-detail"

Best way to solve this is pass category to "categoryFilter" in component, like this:

{% component 'categoriesPreview' categoryFilter= category.name %}

But it's not working... I have no idea how to solve this. Please help :)


Solution

  • For future generation (or just for future myself :)) To display all posts depends on category. Simple use [blogCategories] component. Every category has all blog posts already in object, so its not necessary to call another (post list) component with category filter passed to them.