Breaking your Entries

Here's a quickie I've been meaning to post for a while. From time to time, people ask me, "Hey Brad-- how do you do those dividers inbetween each post for a single day? How do you get MT to do that?"

Well, it's not asked very often since I rarely post twice a day (or even once a day here lately). But here's how you can do it, without using even one of my fantastic plugins.1

Here's what you'd use -- you would put the following above the <MTEntries> closing tag:

<MTDateHeader><MTDateFooter><MTElse>
	<div class="blogbreak"><hr /></div>
</MTElse></MTDateFooter><MTElse><MTDateFooter><MTElse>
	<div class="blogbreak"><hr /></div>
</MTElse></MTDateFooter></MTElse></MTDateHeader>

I'm using a <div> tag around the <hr> tag to allow me to style the thing properly. You can omit the div if you want.

What we want to accomplish is to only produce a horizontal rule inbetween entries for a day. Let's consider all the cases, there are only four:

Day 1
    Entry (header is TRUE, footer is FALSE: break)
    --------
    Entry (header is FALSE, footer is FALSE: break)
    --------
    Entry (header is FALSE, footer is TRUE: no break)

Day 2
    Entry (header is TRUE, footer is TRUE: no break)

The content inside the <MTDateHeader> and <MTDateFooter> tags are only output when either the first entry for the day (header) or the last entry for the day (footer) is being processed. By using the <MTElse> tag, we can exclude the cases where the break is inappropriate.

OK, so what if you don't segment your entries by day? What if you want to simply divide every entry? And naturally, you don't want a break at the top or bottom of the entries. The cases for this scenario are very similar. You just use the "Entries" header and footer tags instead (again, place the following just above the <MTEntries> closing tag):

<MTEntriesHeader><MTEntriesFooter><MTElse>
	<div class="blogbreak"><hr /></div>
</MTElse></MTEntriesFooter><MTElse><MTEntriesFooter><MTElse>
	<div class="blogbreak"><hr /></div>
</MTElse></MTEntriesFooter></MTElse></MTEntriesHeader>

And there you have it.

1 Technically, this is inaccurate. Movable Type's "Else" tag is one of my contributions.

Update: Missed some tags in my example code. Thanks to David Thompson for clearing it up.

TrackBack

TrackBack URL for this entry:
http://bradchoate.com/mt/feedback/tb/859

Listed below are links to weblogs that reference Breaking your Entries:

» More Site Tweaks from LilacRose
First of all, I finally got with it and added permalinks for the comments. See this post on the girly... [Read More]

» MT Entry Breaks from Code Novice
Found this snippet at Brad Choate's and I'm saving it... [Read More]

» MT Entry Breaks from Code Novice
Found this snippet at Brad Choate's and I'm saving it... [Read More]

» MT Entry Breaks from Code Novice
Found this snippet at Brad Choate's and I'm saving it... [Read More]

1 Comments

Twyst said:

How about one for in the Comment templates? I want to put a styled hr between every comment, but as you pointed out, not at the top or bottom. Is this possible? There seems to be no "forward" or "backward" seeking in comments, so I can't do something like (MTCommentPrev)----(/MTCommentPrev) after each comment. Which would be *much* simpler template-wise.

About

This article was published on March 17, 2004 9:35 PM.

The article previously posted was Secure Copy Droplet.

The next article is A simple plan.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type