A quick pagination hack for Movable Type

One of the most common feature requests for Movable Type is entry pagination. It is actually a sticky problem for a system that utilizes static publishing like Movable Type though. *As an aside, I am become very unfond of the term “static publishing” and am coming around to what I think is a more apt term: “pre-emptive caching.”* Anyways, there are a number of well supported techniques for pagination, and the one I send most people to is Mark Carey’s [Pagination plugin](http://mt-hacks.com/pagination.html). But when people feel that is overkill, I often help them implement the following hack.

The hack is simple when you think about it:
* Create a template that outputs a relatively large number of entries.
* Segment the entries into several groups.
* Using some simple template code, wrap each group of entries with a simple PHP statement that will only be evaluated according to the current page being viewed.
It is simple and quick to implement. For example, here is the code I use on Chicago Now to achieve some simple pagination:

<?php if ($page == ) { ?>

You see a [live demo](http://www.chicagonow.com/recent/) on [Chicago Now](http://www.chicagonow.com/)…
**Pros of this method**
* Its free.
* Fast to implement
* Fast page load times
* More page views for your site and more ad impressions
* Achieves desired objective
* The more pages you want your users to be able to navigate back in time, the longer it will take to publish, *cough* I mean cache the page.
* You can’t really go back in time infinitely. You have to choose a reasonable number of pages to allow your users to paginate through. On the plus side, most users most navigate that far back – rarely more than 10 pages in fact.
Anyways, I hope this hack helps you. If you have any questions, or need help, please let me know.


11 Comments on “A quick pagination hack for Movable Type”

  1. Franรงois Nonnenmacher says:

    I used Alden Bate’s Paged Archives Plugin recently. Free, easy to implement and well thought.
    (Very nice live comment preview BTW, where’s the tutorial? ๐Ÿ˜‰

  2. kimonostereo says:

    Thanks for the tutorial on doing this. I’ve seen this mentioned by a few MT devs but since i’m such a hack at php I could never figure it out. This will be very helpful on a few projects!
    I’d also like to know how you’re doing the comment preview ๐Ÿ™‚

  3. Jackie says:

    It’s powerful!
    You can download modified templates from here (http://blog.godbus.com/2009/06/php-pagination-for-movable-type/).

  4. Mike Johnston says:

    I have a quick question Byrne. I’ve attempted to use this code in the mid-century theme but it seems to try to render the php as text. Here’s what I’ve got so far in my main index template.. how do I use your code / where do I put it?

  5. Byrne says:

    Thanks for the pastebin link, but I do not see any PHP code in your templates. If what you describe is correct though, then your web server must not be processing your files as PHP. Are they being published with a .php file extension?

  6. Byrne says:

    @Mike – try this to integrate pagination into Mid-Century: http://pastebin.com/f7cab622b

  7. Chad says:

    Byrne, thanks for this hack. I’m having trouble getting it to render the pagination links in an index template when I add any any category info (single or multiple) to the tag.
    Any advice?

  8. chad says:

    Apologies. Client unpublished many entries leaving me to think pagination wasn’t working. All’s well and this hack does great for me in MT 4.3, FYI

  9. Greeson says:

    It’s always upsetting to hear about these kinds of things.

  10. Tremblay says:

    That’s some pretty funny stuff ๐Ÿ˜‰

  11. Tremblay says:

    That’s some pretty funny stuff ๐Ÿ˜‰

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s