Feature
Post

Category
Code


Make Your Blog More Evergreen with Movable Type

A recent post on ProBlogger discussed the pros and cons of dates on blog posts. The gist of it is recent dates can make posts appear fresh, but a post with an older date might appear stale, even if the information is still relevant.

One option discussed in the article was removing dates from older posts. This seemed like an interesting idea to me, so I set out to see how it could be done with Movable Type. It’s fairly easy, although it does require either a plugin or some PHP code.

Let’s start with the plugin version. We’ll need to install DateTags. This is an older plugin that’s not entirely compatible with MT4. In particular, there’s a problem with the <MTNextNEntries> tag. We don’t need that tag for this, so for our purposes it will work fine.

After you install the plugin, open your Entry Metadata template module and add this code to the top:

<mt:ifarchivetype type="individual">
	<mt:setvarblock name="daysdiff"><mt:deltadays date="[MTEntryDate format='%m/%d/%Y']" target="[MTDate format='%m/%d/%Y']"></mt:setvarblock>
	<mt:if name="daysdiff" gt="180">
		<mt:setvar name="displaydate" value="0">
	<mt:else>
		<mt:setvar name="displaydate" value="1">
	</mt:if>
<mt:else>
	<mt:setvar name="displaydate" value="1">
</mt:ifarchivetype>

Simple, right? Let’s go through it, though, and see what’s going on.

<mt:ifarchivetype type="individual">

MT uses the Entry Metadata template module in a lot of different templates, but I only want to control the appearance of dates on individual entry archives. You can skip this check if you want the change to be site-wide.

<mt:setvarblock name="daysdiff"><mt:deltadays date="[MTEntryDate format='%m/%d/%Y']" target="[MTDate format='%m/%d/%Y']"></mt:setvarblock>

This is the real meat of it. We use the <mt:deltadays> tag from DateTags to find the difference between the entry date and the current date. We then store that value in the daysdiff variable.

<mt:if name="daysdiff" gt="180">
	<mt:setvar name="displaydate" value="0">
<mt:else>
	<mt:setvar name="displaydate" value="1">
</mt:if>

Now we check daysdiff to see the age of our entry. I’m checking if it’s about 6 months (180 days) old, but you can use whatever length you want. We then set another variable, displaydate, based on that age.

A bit further down in our template, we use displaydate to determine, well, whether we display the date:

<MTIfNonEmpty tag="EntryAuthorDisplayName">
	By <address class="vcard author"><$MTEntryAuthorLink show_hcard="1"$></address>
    <mt:if name="displaydate">
    	on <abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$>
    </mt:if>
<MTElse>
        <mt:if name="displaydate">
        	<abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$></abbr>
        </mt:if>
</MTIfNonEmpty>

If you’re using the “About This Page” widget, you’ll want to do the same thing there. Remember, variables declared in one part of a template (or in an included template module) are available to any code that follows, so we don’t have to recalculate the date difference in the widget, just check displaydate.

Using this method, you should get into the habit of regularly republishing your entire blog. That way, older posts will get updated as they “mature.”

PHP Alternative

If for some reason you can’t or don’t want to use the DateTags plugin you can still accomplish this by publishing your entry archives as PHP files. Just use this bit of PHP code to calculate your date difference:

<?php
	$date_diff = round( abs(strtotime(date('y-m-d'))-strtotime('<MTEntryDate format='%m/%d/%Y'>')) / 86400, 0 );
?>

Then use PHP instead of MT to test whether or not to display the date. The nice thing about this option is you don’t have to worry about republishing regularly to make this work — PHP will handle that automatically.

And there are other uses for this technique as well, like changing CSS files based on the age of the entry. You could set up a series of styles that cause your entries to “age” over time.

How do you highlight (or hide) the age of your posts? Let us know in the comments.


  1. By klevo posted on July 26, 2008 at 3:10 am
    Want an avatar? Get a gravatar! • You can link to this comment

    To me hiding such a relevant information is really a bad idea.

    When you write programmers advice, like this one, the older the posts gets the more is the date important. Over time a new releases of MT may come and you need to be able to determine from the date of the post if the information you’re reading is still valid. For example.

  2. By Tom Sieron posted on July 26, 2008 at 5:39 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    I’d second klevo’s opinion. Terrible, terrible idea.

  3. By Billy Mabray posted on July 30, 2008 at 12:27 am
    Want an avatar? Get a gravatar! • You can link to this comment

    klevo, in your example I would agree completely. But did you read the ProBlogger article? He doesn’t use dates on his photography blog, and in that particular case I think it makes sense. How to take good photographs doesn’t change much over time, so dates are far less relevant for that blog. In fact they can be detrimental, since visitors might see an older date and think the information isn’t useful, when it really is.

    For most sites, you’re right, this would not be a good idea. But for a certain type of site, I think it’s a useful technique. Plus, it was an easy way to demonstrate date calculations in MT which, as I mentioned at the end of the post, have other applications.

  4. TrackbackMovable Type Monday: Movable Type 4.2, Pro, Mid Century Theme, Tutorials Galore! | The Blog Herald