I want to create a page that consists of all the posts that my website and there is no pagination and other things. When I am trying to create an archive page by naming archive.hbs
it’s not creating.
You can create a file: page-archive.hbs (and a page in the Admin section with Page URL: archive).
Inside the page-archive.hbs you can fetch all posts like this:
{{#get "posts" limit="all" order="published_at desc"}}
{{#foreach posts}}
<h3 class="title"><a href="{{url}}" class="link">{{title}}</a></h3>
{{/foreach}}
{{/get}}
How can I make a pagination in that archive page. Like in the homepage i get the link page/2
how can I get it in the archive page?
Oh, I misunderstood, I thought you did not want pagination.
In that case disregard the previous answer.
You can add the following in routes.yaml:
routes:
/archive/:
controller: channel
template: archive
data: page.archive
Create the archive.hbs file and loop over the posts:
{{#foreach posts}}
<h2 class="title">
<a class="link" href="{{url}}">{{title}}</a>
</h2>
{{/foreach}}
You should be able to paginate over the posts and you can also include the pagination:
{{pagination}}
I have updated the routes.yml
file.
My file structure
and routes.yml
is like this:
When I am opening /archive
it’s showing the page not found.
If I am publishing a page inside the admin panel > pages
then its opening at /archive
but not showing the pagination.
page-archive.hbs
{{!< default}}
{{#get "posts" limit="all" include="tags,authors" order="published_at desc"}}
{{#foreach posts visibility="all"}}
{{> "posts"}}
{{/foreach}}
{{/get}}
archive.hbs
{{!< default}}
{{#foreach posts}}
<h2 class="title">
<a class="link" href="{{url}}">{{title}}</a>
</h2>
{{/foreach}}
You should delete the page-archive.hbs.
The page in Admin is needed.
For the archive.hbs don’t forget to add {{pagination}}
after the foreach.