【发布时间】:2018-06-05 19:48:10
【问题描述】:
博客分页不起作用。
我有 2 个测试帖子。我将分页设置为每页 1 个帖子。
它在首页显示所有帖子,并创建分页按钮。
点击分页按钮会更改网址,但帖子和页面保持不变。
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
类别过滤器
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;
}
【问题讨论】:
标签: octobercms