27 Aprili 2003

MTEntries

At last and alack, the promised entry on the <MTEntries> placeholder. A good thing to spend an entire entry on: not only is this a crucially important placeholder, its usage ties together most of what I’ve been on about this entire series so far.

The <MTEntries> placeholder represents a list of blog entries, in the abstract. To get concrete, you need to put something inside <MTEntries>. For example, the default MovableType blog template (as of version 2.63) includes a list of the latest ten entries by title in the sidebar. The template code for this is (stolen straight from said template):

<MTEntries lastn="10">
<a href="<$MTEntryPermalink$>"> <$MTEntryTitle$></a><br />
</MTEntries>

See? I bet you can figure out what’s going on there without my saying a word.

(I’m color-coding template snippets to make it easier to tell MovableType placeholders from HTML tags. I hope it helps. Incidentally, I do not recommend that you lift this code-snippet as is. I have issues with <MTPermalink> which I will discuss in a later entry. If you’re already using it, leave it be for now. Said later entry will discuss what to replace it with and why. Plus, I hate the use of the <br /> tag here. Better ways to do this.)

Note all the placeholders starting with <MTEntry>. They’re context-dependent. You can use them inside <MTEntries> and (for your information) inside <MTSearchResults>—and nowhere else. Use them anywhere else and your template won’t work.

<MTEntries> all by itself means the entire list of blog entries for your blog. It fits inside two other placeholders, however, to represent a more restricted list of entries:

  • <MTArchiveList> is a list of all your archive types. If you put <MTEntries> inside it, you access a list of the entries for each archive type. If you use Individual, Monthly, and Category archives, for example, you could use this combination to list the last ten entries ror each of these archive types.
  • <MTCategories> is a list of all your categories. If you put <MTEntries> inside it, you access a list of entries for each category.

The other way to restrict <MTEntries> is with attributes. You can load as many attributes as you like onto a single placeholder; they all add up.

The example above already snuck one attribute in on you: lastn restricts the entry-list to the last however-many entries you specify. Here are the important (in my no-doubt-biased view) other ones:

  • category restricts the list to a specific category. The difference between this and putting <MTEntries> inside <MTCategories> is that this limits the list to the single category you specify, whereas <MTCategories> cycles through every category you have.
  • days limits the list to entries from the last however-many days you specify.
  • sort-order specifies whether to list the first or last entries first. The value ascend starts at the beginning; descend starts at the end. For a newest-posts-first ordering, you want descend.

You may also want to be aware of the following global attributes, which seem to me particularly useful on <MTEntries>:

  • filters lets you filter your entries through various Perl text filters. Nifty, if you happen to have those filters available (ask your webhost).
  • upper_case and lower_case do what they say they do. I prefer to do this with CSS (View Source and look at my entry titles to see what I mean), but unfortunately not all browsers do it properly, so this is a reasonable alternative.

There. Now you know your way around the most important part of your blog template—the entries.