Skip to content

Instantly share code, notes, and snippets.

@eashish93 eashish93/ghostpaginate.md
Last active Jan 11, 2017

Embed
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>
     {{/if}}
     <div class="page-nums">
         {{!-- <a href="" class="current">{{page}}</a>
         <a href="">1</a> --}}
     </div>
     {{#if next}}
     <a class="next" href="{{page_url next}}">Next &rarr;</a>
      {{/if}}
</nav>

<script>
    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>'
        }
        page++;
    }

</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.