Skip to main content

Redesign: Pagination

I had enough posts under my belt on this blog that it was time to introduce pagination. Since I display the full content of my posts on my main page, I chose to only show three per page.

Doing this in CraftCMS was surprisingly easly. I just followed the tutorial in their knowledge base which had me up-and-running in no time.

This entailed me changing the way I accessed posts to this:

{% paginate craft.entries().section('blog').limit(3) as pageInfo, pageEntries %}

Then adding this to the bottom of my main-content area to provide for the actual paging.

    {% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}">Previous Page</a>{% endif %}
    {% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}">Next Page</a>{% endif %}

After a small bit of style tweaking for the links at the bottom, it was all done.

Pagination to previous/next post

All I needed after that was a link at the bottom of a single post, to link to the previous/next one. And it was pretty much the same exact code, so not worth repeating.

Next Up

There are some tweaks here and there I'll get around to at some point, but I think this will be the last post about the build-up of the new site. Maybe I can get a designer friend to do up something a bit fancier for the design at some point down the road.

For my day job, I primarily develop in Ruby on Rails, so I'll start posting more about Ruby/Rails.