Hello,
I’m using source theme (v1.4.1) for my self-hosted Ghost blog https://thenetworthblog.com/. How can I add pagination in homepage? I set the ““posts_per_page”: 10,” in package.json file.
Currently i’m using the following code in the routes.yaml file
"routes:
/: home
collections:
/:
permalink: /{slug}/
template: index
Hello Cathy,
Thanks for quick response.
Actually I’m newbie with Ghost CMS. Would you please explain more or give me any tutorial on How can I add pagination in source theme?
or, if its not possible in source theme, can you recommend any other similar theme that comes with similar features and built-in pagination option?
Also, Always changing a theme needs to update the routes.yaml file? I’m asking this because I just tried a different theme “casper” but when I active the theme, the homepage showing 404 not found error.
Source /should/ paginate, it just won’t respect settings in package.json for the first page (and you probably don’t want to change it, because there are some hard-coded assumptions about what the posts per page is). It is /the/ hardest of the official themes to work with. There’s a bunch of extra layout-specific logic. You might look at Casper instead, if you want something easier to work with. It has fewer layouts available,
For Source, I think I saw a bug report about posts between 10 (12?) and 15 going missing, and then everything was OK once the site had >15 posts. So if you ignore the problem and post a bit more, it may start paginating.
Casper respects routes settings and you can set the number to paginate on in package.json, if you don’t like the default. The reason it is throwing an error for you is that you have a ‘home’ template in your routes file, but Casper doesn’t have a home.hbs. You can just remove the entry in the ‘routes’ section. You don’t need it anyway. (It isn’t actually doing anything in Source either, since Ghost uses the home.hbs template for the / route anyway.)
Each theme will typically come with a routes for that theme, so if you make custom and want to change themes you would need to rebuild that to include your routes changes.
Could you please share your routes.yaml (best to download from ghost > settings > labs to be sure you’ve got the active version) and what your posts per page is set to in package.json? Thanks!
(Sorry, I see you shared your routes file previously. If that’s what you’re using, no need to repost.)
And in Package.json, I tried to set post limits by 10, 12 and 15. None of these works. After setting the post limit in package.json, I also restart ghost, but not works.
Then I added your routes file, and got the result you’re seeing. I removed the first line under routes, and then it worked. So your routes file needs to be:
So, please remove that line and you should be good!
More technical explanation, for anyone interested:
I think what’s going on here is that when you set up a routes entry for / and point it at the home template, you don’t actually get a collection at /, but instead, you get well… basically nothing, if you don’t set the ‘data’ attribute for it. HOWEVER, because Source makes a #get request for all the posts it is going to display, the problem is not obvious. But Source does check pagination to decide if you need a ‘see all’ link. Since there’s no collection of posts at that url if you have a ‘route’ instead of a ‘collection’ for home, you get no ‘see all’ button because pagination says there are no posts, since you’re viewing a route, not a collection. Does your head hurt now? Mine does.