At the bottom of each post on this blog is a Where next? section. One of the options given is a link to the previous and next entries in the blog.
I’m fairly new to Movable Type on which this blog is based, but I am familiar with several other templating languages. I wanted to provide a link to the previous entry (post) if it exists, a link to the next entry if it exists, and a separator between the two if they both exist:
- At the beginning (earliest): next »;
- Somewhere in the middle: « previous || next »;
- At the end (most recent): « previous;
MT provides the mt:EntryPrevious and mt:EntryNext template tags which, in the context of an entry, change the context (think subject of conversation) to the previous or next entry. If that entry does not exist, the content of the tag (should really be element) is ignored.
Simple enough, but how do we implement the separator that should appear only if both previous and next entries exist? Here we go:
<mt:EntryPrevious>
<li>
<a href="<mt:EntryPermalink />">« Previous</a>
<mt:EntryNext>
<mt:EntryNext> || </mt:EntryNext>
</mt:EntryNext>
</li>
</mt:EntryPrevious>
<mt:EntryNext>
<li>
<a href="<mt:EntryPermalink />">Next »</a>
</li>
</mt:EntryNext>
</ul>
What’s going on here? We start an unordered list which is separately styled as a simple inline, non-bulleted list. We enter the EntryPrevious context, which is only evaluated if there is a previous entry — on the very first entry in the archive, this bit is skipped altogether. We then write a simple link to the previous entry (« is the left double-bracket “«”).
Now comes the clever bit: whilst still in the context of the previous entry, we dive into two nested EntryNext elements, which are relative to the EntryPrevious context we were in. These take us back through the current entry to the next one if it exists, where we write out the separator. This bit is only accessed if we’ve successfully found a previous entry and managed to navigate forwards two entries from that.
We finish off by coming out of the two EntryNext contexts, then out of the EntryPrevious context. Finally, we jump back into the EntryNext context to write the link to the next entry, regardless of whether the previous one exists or not.

Thank you! I am working on getting my photoblog customized in MT 4 and for the life of me could not figure this one out. Thanks a ton for doing a how to. I plan on doing one for the photoblog once it is up and running.
Thank you for the great how to and tutorial!