Set it and forget it
- At a glance
- This entry was written on January 29, 2006.
- The entry prior to this is entitled Zenphoto 1.0.1 (beta).
- The entry following this is entitled Why I stick with MT.
- There are 0 comments on this post.
- This entry has been tagged as Blogs, MovableType, Recommended, Work, XHTML, examples, php.
- Archives are also available.
One of the fun things about setting up my sister's website is using her site as an excuse to hack away at Movable Type a little more.
All the hacking's fun, but it also serves a practical purpose since our embryonic company will be offering similar services. One of the most important things I wanted to figure out was how to set up things up from the start like registry lists and blog archive navigation that wouldn't be needed until later on down the road.
In essence, I wanted to be able to set the site up once and then just let it sort of run itself.
I'd like to be able to do this sort of thing directly in Movable Type, using tags such as <MTIfNonEmpty> and <MTElse>. Unfortunately, you can't (as far as I can tell) use them to hide things until a certain number of entries are written—which is kind of the point of this exercise.
Enter PHP and plugins.
No nav until you need it
For the blog section of my sister's site, I wanted to display five entries at a time on the front page and keep all the archives listed on the front page in the sidebar (I'm working on the assumption that my sister's not going to be updating a heck of a lot, so that plan makes sense).
So, in the sidebar of her blog (or "Updates" section in this case), I originally tried the following code:
<MTIfNonZero tag="MTEntries offset="5"">
<h3 class="subhead">Older Updates</h3>
<ul>
<MTEntries lastn="1000" sort_order="ascend" offset="5">
<li>
<a href="<MTEntryPermalink>">
<$MTEntryDate format="%m/%e/%y"$> — <$MTEntryTitle$>
</a>
</li>
</MTEntries>
</ul>
<MTElse><p> </p></MTElse>
</MTIfNonZero>
Nothing too earth-shattering here, and it's the sort of thing that you'd expect to work.
However, a lot of MT's utility tags won't work with attributes applied to interior tags. <MTIfNonZero> and <MTIfEmpty>, in fact, seem more intended to control output if an author leaves out, let's say, a title. In my light experimentation, it seems like it won't work that well with MTEntries in general.
You could, theoretically, use the Compare plugin to set up something like this:
<MTIfGreater a="[MTBlogEntryCount]" b="5" numeric="1">
<h3 class="subhead">Older Updates</h3>
<ul>
<MTEntries lastn="1000" sort_order="ascend" offset="5">
<li>
<a href="<MTEntryPermalink>">
<$MTEntryDate format="%m/%e/%y"$> — <$MTEntryTitle$>
</a>
</li>
</MTEntries>
</ul>
<MTElse><p> </p></MTElse>
</MTIfGreater>
This block basically just checks my new favorite MT tag, <MTBlogEntryCount>, which outputs a the number of entries written in one specific blog, against any arbitrary number you wish (in my case, five).
I haven't tested this idea, since I went the PHP route, but it should work.
Since I've been spending a lot of time lately learning the very basic ropes of PHP, I went that route with a block of code like this:
<?php
$count='<MTBlogEntryCount>';
if ($count > 5) {
print('
<h6>Older Updates</h6>
<ul>
<MTEntries sort_order="ascend" lastn="1000" offset="5">
<li>
<a href="<MTEntryPermalink>">
<$MTEntryDate format="%m/%e/%y"$> — <$MTEntryTitle$>
</a>
</li>
</MTEntries>
</ul>');
}
else {
print('
<p> </p>');
}
>
Which does essentially the same thing as the Compare plugin lets you do.
For my sister's registries, I can do the same thing, but set the number to one instead of five—that way the list won't show up until she's ready to add a link.
Post a comment