I’ve created a custom template for an archive page. I’ve got it all working basically the way I want, EXCEPT that I can’t get pagination to work.
I have renamed the pagination.hbs file in the partials (pagination_old.hbs) so it should use the default pagination.
Here is the code for the template page. If I uncomment the {{pagination}} helper, I get a 404 error. Thoughts?
(Note: This uses the custom CSS shared elsewhere to get the posts grouped by month, which works well.)
{{!< default }}
<div><h2>Archive of All Posts</h2><i>Organized by month</i><br/><hr style="border:solid 1px black; clear:both; display:block; width: 96%; color:black; height: 2px; margin-top:12px;"></div>
<div>
{{#get "posts" limit="all" include="tags" order="published_at desc"}}
{{#foreach posts visibility="all"}}
<article class="post post-date-{{date format="M"}}">
<div class="post-label" style="font-size:18px; margin-top:10px; color:darkblue;"><b>{{date format="MMMM YYYY"}}</b></div>
<a class="post-link" style="font-size:14px;" href="{{url}}"><b>{{title}} </b></a><i style="font-size:14px;">({{tags}})</i>
<p style="font-size:12px; margin-left:14px;">{{excerpt}}</p>
</article>
{{/foreach}}
{{/get}}
</div>
{{!-- {{pagination}} --}}
The pagination helper depends on its context (posts or tags, for example). I don’t think it’s going to work here on a custom page. Also, if you’re fetching all posts, there wouldn’t be anything to paginate because all the posts would already be on the page.
But maybe I’m missing something in what you’re trying to do?
I’m trying to build an archive page of all posts, grouped by month. I started with this article, and did my own adjustments. He’s using pagination on an archive page, so I assumed it would work here as well. (Of course, it’s used on most home pages as well, which are custom pages.)
He has the pagination helper outside the #foreach loop. I’ve tried it pretty much everywhere, but no matter where I put it, I get a 404 whenever I refresh the page. What am I missing?
There’s two examples on that page.
You’re using the technique from the first example, which doesn’t use the pagination helper, since it loops through all posts on one page.
The second example can use the pagination helper because it implements custom routing (via routes.yaml). I think that’s the piece of the puzzle you’re missing. You need to set up a custom route for the pagination helper to work. You would also want to follow the guide’s placement of the get and foreach helper, as they’re different than in your setup.
1 Like
Yep – that was the problem. That, and being unsure whether I needed a standalone page, or a template and published page.
Finally got it to work, and it looks pretty much the way I want. The pagination code at the bottom is butt-ugly, but I’ll leave customizing it for another day.
Thanks for your help!
1 Like