Skip to content

Instantly share code, notes, and snippets.

Last active February 9, 2023 06:15
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ghost numbered pagination

Hye, this is custom numbered pagination with first, next and prev links. Also the user can limit the pagination numbers. Just include this code in pagination.hbs file inside ghost theme partials directory. Any improvements are always welcome.

{{!-- custom pagination file --}}

<nav class="pagination" role="navigation">
    {{#if prev}}
    <a class="prev" href="{{page_url prev}}">&larr; Prev</a>
     <div class="page-nums">
         {{!-- <a href="" class="current">{{page}}</a>
         <a href="">1</a> --}}
     {{#if next}}
     <a class="next" href="{{page_url next}}">Next &rarr;</a>

    var pageTotal = parseInt("{{pages}}"),
        pageCurrent = parseInt("{{page}}"),
        limitPage = 5,
        page = 1,
        pageNums = document.querySelector('.pagination .page-nums');

    if(pageCurrent >= limitPage) {
        page = pageCurrent - 1;
        pageNums.innerHTML += '<a class="first" href="{{page_url}}page/' + 1 + '">First</a>';

    for(i = 0; i < limitPage; i++) {

        if(page === pageCurrent) {
            pageNums.innerHTML += '<a class="current" href="{{page_url}}page/{{page}}">{{page}}</a>';
        else if(page <= pageTotal){
            pageNums.innerHTML += '<a href="{{page_url}}page/' + page + '">'  + page + '</a>'

Copy link

kuzyk commented Aug 16, 2022

as for me this solution is simple

<div class="blog-pagination">
    <a href="{{page_url prev}}" class="back"></a>

    {{#foreach '____________________________________________________________' from=1 to=pages}}
        <a href="{{page_url @number}}" class="{{#match @number '=' ../page}}current{{/match}}">

    <a href="{{page_url next}}" class="next"></a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment