Blog Pagination is not working.
I have 2 test posts. I set pagination to 1 post per page.
It displays all posts on the first page, and creates pagination buttons.
Clicking pagination buttons changes the url but posts and pages remain the same.
HTML
{# Blog Post List #}
<ul class="post-list">
{% for post in filteredPosts %}
<li>
<h3><a href="/blog/{{ post.slug }}">{{ post.title }}</a></h3>
<p class="info">
Posted
<!--{% if post.categories.count %} in {% endif %}
{% for category in post.categories %}
<a href="{{ category.url }}">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
{% endfor %}-->
on {{ post.published_at|date('M d, Y') }}
</p>
<p class="excerpt">{{ post.summary|raw }}</p>
</li>
{% else %}
<li class="no-data">{{ noPostsMessage }}</li>
{% endfor %}
</ul>
{# Pagination #}
{% if posts.lastPage > 1 %}
<ul class="pagination">
{% if posts.currentPage > 1 %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage-1) }) }}">← Prev</a></li>
{% endif %}
{% for page in 1..posts.lastPage %}
<li class="{{ posts.currentPage == page ? 'active' : null }}">
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
</li>
{% endfor %}
{% if posts.lastPage > posts.currentPage %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage+1) }) }}">Next →</a></li>
{% endif %}
</ul>
{% endif %}
PHP
Category Filter
use RainLab\Blog\Models\Post as BlogPost;
function onStart(){
//This is where you list the categories you want to display
$categories = ['blog'];
$posts = [];
foreach(BlogPost::all() as $blog){
foreach($blog->categories as $cat){
if(in_array($cat->slug, $categories)) {
array_push($posts, $blog);
break;
}
}
}
$this['filteredPosts'] = $posts;
}



