Movable Type Tips and Hacks

  1. Movable Type Resources
  2. Plug-ins & Templates
  3. Style sheets
  4. Example Sites
  5. Tips & Hacks

More pages like this one .....
RSS Workshop
RSS Searching Workshop
Utah test channels - other popular channels
Movable Type: Examples - Tips & Hacks
Drupal: Glossary, Examples, Resources, Themes
Geeklog
Forums
FAQ Managers
Accessible CSS Examples
XHTML Examples
Photoblogs: Examples - PhotoPost - Gallery - 4Images
Tools for Webmasters

Movable Type Tips Resources

Movable Type Support Forums

 

Girlie Matters - Tips, Tricks

 

Brad Choate Movable Type Tips

 

Brenna Koch's EmptyPages, particular her Movable Type Tips
See also her MySQL, scripting, PHP, template, and tags hacks at this page.

 

Accessibility Hacks

Mark Pilgrim's Dive Into Accessibility: 30 days to a more accessible web site is an online book. He has tips for all publishing tools, and in particular, tips for Moveable Type, GrayMatter, Radio Userland, and Blogger.

Archiving Content

Blog editors, as a precautionary measure, can make personal archives of their own channel content. Pam does this routinely for her Library News and Ferret channels. This tip is also particularly easy and useful for moving content between blogs or to move MT content from one server to another.

To do so, click the MT Admin "Import/Export" button, and then click the "Export Entries" at the bottom of the page. Hold down the option key on the Macintosh, or the Shift key on a PC, while clicking on the link.

Note: Be sure you use a web browser such as Netscape, Opera, or Mozilla. All versions of Internet Explorer have a bug where data marked as plain text can be intrepreted as HTML. The symptom of this bug is that all of your exported data will run together onto one line.

 

Categories

See User Manual. If you give a category a description, you can use the MTCategoryDescription tag inside of an MTCategories container to display the description. Use the <$MTEntryCategory$> tag to get the category name to display after the author name and date/time stamp.

Creating Subcategories

David Raynes' MTOtherBlog plug-in allows to use content from multiple other blogs in your own blog as long as they are on the same server installation of Movable Type. One use is for creating subcategories. Once installed, treat the other blogs on the server installation as primary categories, and their ordinary categories now become subcategories. Here is David's coding example of how to do this from the user forums:

<MTOtherBlog blog_id="2,3,4">
<h2><$MTBlogName$></h2>
<MTEntries lastn="2">
<$MTEntryTitle$><br />
<$MTEntryExcerpt$><br />
<br />
</MTEntries>
</MTOtherBlog>

 

Creating RSS Feeds for Categories

This tip comes from Ben Trott and Girlie. You can syndicate feeds by category using MT's Multiple Archive Templates feature.

  1. Go to List Templates and select your RSS template for editing (eg. index.rdf). Select and copy the code in the Template Body window.
  2. Go back to List Templates and select Create new archive template. Give the template a name such as Category RSS. Paste the code from your RSS template into the Template Body window, and select SAVE.
  3. Go to Blog Configuration | Archiving and select ADD NEW. In the popup window, choose Category for the archive type and Category RSS for the template. Click ADD. This adds a new category template to your list that is visible in the Archving configuration window.
  4. Click the radio button next to the new template you've just added, and in its field for Archive File Template, enter this code:
    <MTArchiveCategory dirify="1">.xml

    Click the radio button for Category Archive, and in its field for Archive File Template, enter this code:

    <MTArchiveCategory dirify="1">
    SAVE your changes.
  5. Rebuild your Category Archives. MT will generate an XML file for each category in your archives folder.
  6. You can list these feeds on your site main index (index.html) or elsewhere using the following code:
    <MTCategories>
    <a href="<MTBlogArchiveURL><MTCategoryLabel dirify="1">.xml"><MTCategoryLabel></a><br>
    </MTCategories>

    so for example, to create a new section listing RSS feeds for your categories, you can insert:

    <div class="sidetitle">Category RSS Feeds
    </div>
    <div class="side">
    <MTCategories>
    <a href="<MTBlogArchiveURL><MTCategoryLabel dirify="1">.xml"><MTCategoryLabel></a><br />
    </MTCategories>
    </div>

    Another option would be to have MT generate a list of your categories, with links to the category archives, followed by an orange XML icon that links to the RSS feed for that category. To that put the following code into your main index page:

    <div class="sidetitle">Categories
    </div>
    <div class="side">
    <MTArchiveList archive_type="Category">
    <a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a> <a href="<MTBlogArchiveURL><MTCategoryLabel dirify="1">.xml"><img src="./images/tinyxml.gif" border="0" width="16" height="7" /></a><br />
    </MTArchiveList>
    </div>

    This site shows the end result. To put in the larger, orange icon substitute <img src="./images/xmlicon.gif" border="0" width="36" height="14" />


Curly Apostrophes

Mark Pilgrim provides this tip using Brad Choate’s MT-regex plugin to automatically turn straight apostrophes curly. Install the plug-in, then then create a new template module called curlyquotes that contains this code:

<MTAddRegex name="apos1">s/'([dmst])([ .,?!\)\/<])/&#8217;$1$2/gi</MTAddRegex>
<MTAddRegex name="apos2">s/'([lrv])([el])([ .,?!\)\/<])/&#8217;$1$2$3/gi</MTAddRegex>

Then, in each of your templates, add this at the top:
<$MTInclude module="curlyquotes"$>
And anywhere you have this:
<$MTEntryBody$>
Change it to this:
<$MTEntryBody regex="1"$>
Apostrophes can be typed straight, and will show up straight when editing, but they will be published as curly.

New Entry Full Text Display

Terry Davis discovered that, by default, Movable Type RSS feeds only show the first 20 words (about 100 characters) of item descriptions. If you want your feed item descriptions to include their full text, edit your feed templates (index.rdf and index.xml) by substituting MTEntryBody for MTEntryExcerpt. Here an example showing the differences between the two when parsed. MTEntryBody is wrapped by <p> by default. If you want to eliminate this spacing, go to preferences and in the blog config and turn off "Covert Line Breaks." You may want to turn it off in MT, and if you want spacing in your blog channel, achieve that using CSS.


Linking to Next N Entries

Here's a code snippet you can use to display links to the next N entries in your blog (as I use it in my sidebar for "Other Recent Entries"):

<MTEntries lastn="10" offset="15">
<a href="<$MTEntryLink$>">
<$MTEntryTitle$></a>
<br></MTEntries>

Since I display the last 15 entries in my blog, I wanted to display the next 10 in my sidebar (i.e., entries 16 to 25). Combining lastn with offset is what makes it work. Change 10 and 15 to meet your needs. - Source -


Permalink Links

Ever notice how some blogs display "permalinks" that are URL references to the story being cited? Well, by default, all MT blog entries have this permalink link, but for some mysterious reason it is linked via the time stamp. This is very unintuitive for the user. I added the permalink wording by simply making this change to one line in the index template:

<div class="posted">Posted by <$MTEntryAuthor$> at <$MTEntryDate format="%X"$> | <a href="<$MTEntryPermalink$>">Permalink</a>

 

Powered by Movable Type

Movable Type defaults with the textual attribution. If you want to use a graphic, such as , then add this to your index template.

<div class="powered">
<a href="http://www.movabletype.org"><img alt="Powered by Movable Type 2.51" src="mt.gif" width="128" height="22" border="0" /><br />
<$MTVersion$></a><br />
</div>

Depending on the stylesheet you are using, you may need to make changes there as well. I had to change my powered class in these ways:

.powered background to #FFFFFF from #D3D3D3
border-left:1px dotted #999; from border:1px dotted #999;

 

RSS Feed Links

The open source templating feature of MT, allows users to easily customize templates for constructing XML feeds that conform to any RSS standard. Out of the box, MT comes with templates for RSS 1.0 and 0.91 feeds, but only displays the RSS 1.0 feed. If you want to display the other, you can make this change to the index template (see example). I've also added the RDF and XML graphical icons as well. The wording and graphics are up to you. If you have a template for RSS 2.0, please share it here, too.

<div class="syndicate">
<a href="index.rdf"><img src="rdf.gif" border="0" width="36" height="14" /> Syndicate this site RSS 1.0</a><br />
<a href="index.xml"><img src="xmlicon.gif" border="0" width="36" height="14" /> Syndicate this site RSS 0.91</a><br />
</div>

 

Use PHP to selectively show or hide content based on MT category

Patricia discovered this php snippet when she implemented the ScriptyGoddess show/hide script.

<?
if ( xxx == xxx ) {
?>
...stuff...
<? } ?>

My latest bit of witchery allows me to have only certain information show up on a page. For example, the blog that publishes the static pages of my site (about, contact etc) and the writing in the writing section is set to individually archive entries. The problem is that I only want a feedback form and the creative commons license info to show up for those entries tagged with the 'writing' category. So, the above php snippet to the rescue. I added the MT category code to the Individual Archive template, but commented it out because I don't want it to show. Then I surrounded the feedback form and cc info with the following:

<?
if (<$MTCategoryLabel$> == "writing") {
?>
...feedback form...
...cc info...
<? } ?>

So when the page gets published, the entry category is checked, and if it matches 'writing', the form and creative commons license info shows up. By repeating the php snippet and changing the category type to be matched, you could have information show up for several different categories, I would imagine. Though I haven't tried this out yet. See for yourself:
entry not tagged as 'writing'
entry tagged as 'writing' with feedback form and cc info

Use PHP to check for upcoming events

LC uses a snippet of PHP to check for upcoming events (based on entry dates) for the next week in a template:


<?php
$now=date("Ymd",time()-24*3600);
$seven=date("Ymd",time()+7*24*3600);
?>
<MTEntries lastn="99">
<?php
$entry=date("<$MTEntryDate format="%Y%m%d"$>");
if (($now<=$entry) && ($entry<=$seven)) {
?>
<a href="<$MTEntryLink relative_url="1" archive_type="Daily">"><$MTEntryTitle$></a><br />
<? } ?>
</MTEntries>

Determine the date one day earlier, and the date one week from now

Current date = MTDate format='%m/%d/%Y'

To check for upcoming events (based on entry dates) for the next week, try using SomeDays plubin in conjunction with Compare plugin, letting SomeDays get you the dates (eg. <MTSomeDays select="week">) , and Compare determine if its within the right range.

<MTSomeDays select="7" offset="-1">
<MTEntries>
<a href="<$MTEntryLink relative_url="1" archive_type="Daily">"><$MTEntryTitle$></a><br />
</MTEntries>
</MTSomeDays>

First you set the date to one week from today. You can accomplish this by use of the offset or week attributes. You've used the offset in your example, but week="next" would also move the date forward one week. Now your current date within the plugin is set one week forward - continuing our example with today as the date, you have 9/21/2003 as your current date. Using a negative number moves the date forward, while a positive number moves the date backwards. You then tell the plugin how much data to return. You use select="7", which pulls in 7 days, ending with the current date. No negatives are allowed in the select, as I think you can do what you need with the other attributes. For instance, if you'd like to go two weeks forward, use offset="-2" to set your date (to 9/28 if running today). If you leave select="7", you'll skip next week, and pull in the week after. If you use select="14", you'll select everything from now until then.




Limit entries automatically after 40 words and create an extended entry

From Tips and Tricks.

  1. Go to your Weblog Config, and then to Preferences. Scroll down until you see "Enter the number of words that should appear in an auto-generated excerpt." In the box next to that put in "40" or whatever number of words you want the excerpt to be.
  2. Put the <$MTEntryExcerpt$> code into your template. You can have this code link to the full entry by including <$MTEntryPermalink$> after it. From the MT manual:

    MTEntryExcerpt
    The excerpt of this entry. If you have not provided an excerpt for this entry, the first 20 words of the entry, followed by an ellipsis (...) will be used, instead.

The default setting for this tag is 20 words, but you changed it to 40 words in the previous step. This means that as long as you have the MTEntryExcerpt tag on your page, you can type as long an entry as you want in the Entry box, and it will still only display the first 40 words. So your main index page might look like this:

<MTEntries>
<b><$MTEntryDate$></b>
<br>
<$MTEntryExcerpt$><a href="<$MTEntryPermalink$>">...</a>
</MTEntries>

To List the Next "n" months of Future Events

LC said that I solved this using a modified version of Brad Choate's "Year archives" perl code. MT only creates monthly archives. For a year archives, you need to create an index template for each year. Brad uses the PerlScript plugin to do the work of this. See Brad's code.

LC took his technique with his MTperlscript plugin and made it project this month and the next two months into mini-calendars. I even found a followup to modify the code so the month name headers could be clickable to go to a fullsize calendar page. It's a snippet that you insert into the original code [assumes your existing code is basically the same as brad’s example]: The new code is in bold. The modification is:

sub month {
my ($month, $blog) = @_;
my $date = MT::Util::format_ts(“%B %Y”, $month.’01010101’,$blog);
my $file = MT::Util::format_ts(“%Y_%m.php”,$month.’01010101’,$blog);
my $title;
if (-f “/physical/path/to/your/monthly/archive/$file”) {
$title = qq{<a href=”/url/to/your/monthly/archive/$file”>$date</a>};
} else {
$title = $date;
}

# you can customize the format of your calendar by
# changing the HTML below. Note that the ‘MT’ tags
# have been altered to ‘ZZ’ instead so they aren’t
# evaluated BEFORE the Perl code is executed:

you’ll need to alter the format_ts(“%Y_%m.php”… part to suit your own file-naming convention, and also insert the correct physical path and url in the indicated places.Then you also need to change the line:

<th colspan=”7”><span class=”calendarhead”>$date</span></th></tr>
to
<th colspan=”7”><span class=”calendarhead”>$title</span></th></tr>
and then rebuild.

 

To Display the Next Future Events

LC says that the reason why Brad's code works so well is that it uses the ability of MT to specify the exact month you want the calendar for. I just modified his code to determine the current month and then show the next two. To display the next "few future events", you could just copy the technique I use in the events listing that I manage. I simply use some php code to cut off events that are before the date I want or much further afterwards:

<?php
$now=date("Ymd",time()-24*3600);
$thirty=date("Ymd",time()+30*24*3600);
?>
<MTEntries lastn="99">
<?php
$entry=date("<$MTEntryDate format="%Y%m%d"$>");
if (($now<=$entry) && ($entry<=$thirty)) {
?>

and at the end of the MTentries it should look like this:
<? } ?>
</MTEntries>

The above code is a derivative of the work I found at Sillybean (see below)



Using Movable Type as an events calendar

From Sillybean:
There are a couple of ways of using Movable Type to create a calendar of events. One is to display future events as text entries, replacing the traditional bloggish today-going-backwards posting order. The key to this is the fact that MT allows you to change the date on a post, even to a future one. The other way is to change a blog's monthly archive template to display in a calendar-style layout. Note that if you want your events calendar to appear in a sidebar of your existing text blog, you will need to create a separate blog for the calendar and use includes to put it on your index page. The instructions below will change the configuration of your entire blog. Use at your own risk!

Part one: the future events listing . Example: Exploit Boston.

Example: Exploit Boston

- With the default MT settings, your events will display entries from the farthest in the future and backwards. To turn it around and display posts from now going forward, go to Blog Config -> Preferences and change the order of posts to "Ascending." Another (less drastic) way of doing this is to rewrite your MTEntries tag:
<$MTEntries sort_order=”ascend”>

- There are two ways to show the upcoming events and hide the past ones: categories (manual) or date-based (automatic, requires PHP).

For categories:
- Establish a category for current/upcoming events. (We'll call it 'upcoming'). If you don't have any other categories, create some (like 'deadlines' or 'events').

- In your main index template, change <MTEntries> to <MTEntries category="Upcoming">. Now the only entries that will be displayed are those that are in the Upcoming category. You will need to edit each entry and remove it from the Upcoming category in order for the entry to "expire."

- When you post an entry, assign its primary category as something other than upcoming. Save it. Now edit the entry: change the date to the date of your event, and use the "assign multiple categories" button to assign it to Upcoming. Save the entry again.

- When the event has passed, edit the entry again and remove it from the Upcoming category.

For automatic expirations using PHP:
Again, two options here. You can have posts expire at a time you set, down to the second, on the day they take place; or you can have them expire at the end of the day. (If you don't really care, go with the second option; it's much easier to maintain.)

Option 1 (from ScriptyGoddess - see below): In your template, add this PHP snippet inside your <MTEntries> tags: <MTEntries>
<?php if (time() <= strtotime ("<$MTEntryDate format="%B %e, %Y %I:%M %p"$>")){ ?> . .
(keep your existing code here) . <? } ?> </MTEntries>

Be sure to change your template's output file to .php if it wasn't already. Save and rebuild.

Note that because the PHP code compares the time stamps down to the second, you will need to edit the time (not just the date) of your future entries. If you want the entry to scroll off the main page the very minute a deadline has passed (e.g. 5 pm), you will need to set the time to 17:00:00. If you want the entry to remain on the page until the next day, set the time to 23:59:59.


Option 2:
In your template, add this PHP snippet inside your <MTEntries> tags:
<MTEntries>
<?php
$now=date("Ymd");
$entry=date("<$MTEntryDate format="%Y%m%d"$>");
if ($now<=$entry) {
?>

.
. (keep your existing code here)
.
<? } ?>
</MTEntries>

Be sure to change your template's output file to .php if it wasn't already. Save and rebuild.

See this MTForums thread for more details.


Archives will always go from latest to earliest, even if you change the display order of your posts in your preferences. You can check this thread for some ways to rearrange your archives using PHP.



To Display Future Events

This MT Forum thread suggests.

Timothy Appnel said: setting days to -1 produces all entries with a future timestamp.
<MTEntries days="-1">
<a href="<$MTEntryLink$>"><$MTEntryTitle></a><br/>
</MTEntries>

Tom says that Timonthy's solution is the simplest and works like a charm. It displays all future events, however, this can be a long list.

Frugle suggests:
Create a new index template that you can include with SSI or PHP as in:

<div class="head">Events - <$MTDate format="%B %Y"$></div>
<div class="body">
<MTCalendar month="200207" category="Events">
<MTCalendarWeekHeader>
</MTCalendarWeekHeader>

<MTCalendarIfEntries>
<MTEntries lastn="1">
<$MTCalendarDay$> <a href="<$MTEntryLink$>"><$MTEntryTitle$></a><br />
</MTEntries>
</MTCalendarIfEntries>
<MTCalendarIfNoEntries>
<$MTCalendarDay$><br />
</MTCalendarIfNoEntries>
<MTCalendarWeekFooter></MTCalendarWeekFooter>
</MTCalendar>
</div>

Omiting month= will display current month.
Omitting category= will display all categories

If you're making "older" records they won't need updating every time you rebuild, so uncheck it when you create the template. Tom says, though, that Frugle's code displays the month's events in list format, regardless of whether the event has passed or not.

Trailgirl says all you need to do to get a list of upcoming events is to take the ScriptyGoddess suggestion for displaying at a future date (below) and reverse the date checking: use less than instead of greater than, as in:

<?
if (time() < strtotime ("<$MTEntryDate format="%B %e, %Y %I:%M %p"$>"))
{
?>

Then, an entry for an upcoming event shows up, but not if the event date has passed.

 

 

Post entries for display at a specific future date

From ScriptyGoddess:
(1) "Install" the script below. (wanted to give you the instructions first, before I threw a bunch of code at you... so skip ahead to the code to do the installation...)

(2) Write your post, but save it as a draft.

(3) Once saved, you can edit the "date" of the post. Change the date to whatever day you want your post to actually show up.

(4) This time you save it, with "publish" as the Post Status instead.

That's it. It won't show up on your blog, until it's the date you set. NOW the code... There's alot of code (update: actually now there's ALOT less since I've updated it!), but no customization... you just need to copy and paste it in the right spot to get it to work... So, it's not as scary as it looks... ok? I promise. :) (the code below is shown as an example of what goes on the index template... additional code will probably be required if you use individual entries and you don't want to have it show the "next" entry (until it's the right time) on the previous post.) I'll put it on my "to-do" list, which just gets longer and longer...

After your <MTEntries> tag, put the code as you see it below (I included the MTEntries tag, just for reference...) (please see commented notes below for what goes where). The code you need to paste is in red (the "existing tags" are in black)

<MTEntries>
<?
if (time() > strtotime ("<$MTEntryDate format="%B %e, %Y %I:%M %p"$>"))
{
?>
<!-- PUT THE REST OF YOUR MT TAGS FOR YOUR POST BELOW -->
<MTDateHeader>
<h2><$MTEntryDate format="%B %d, %Y"$></h2>
</MTDateHeader>
<a name="<$MTEntryID pad="1"$>"></a>
<h1><$MTEntryTitle$></h1>
<p><i><$MTEntryDate format="%I:%M %p"$></i></p>
<$MTEntryBody$>
<MTEntryIfExtended>
<p><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>">MORE...</a></p>
</MTEntryIfExtended>
<p align="right"><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>">permalink</a>
<MTEntryIfAllowComments> | <a href="<$MTEntryLink$>#comments">
<$MTEntryCommentCount$> comments
</p>
</MTEntryIfAllowComments>
</p>
<br>
<!--- END OF ALL YOUR MT TAGS FOR YOUR ENTRY -->
<!-- Make sure you add the next little lines below BEFORE your put your "/MTEntries" tag. -->
<? } ?>
</MTEntries>

To Send this Story to A Friend

<!-- Javascript that GWB uses to open a popupwindow to send the story to a friend -->
<!-- eg. http://www.georgewbush.com/blog/archives/send000083.html -->
<!-- requires Macromedia's getflashplayer plugin for x-shockwave-flash>
<!--script language="javascript" type="text/javascript">
function OpenPopup (c) {
window.open(c,
'sendtofriends',
'width=380,height=450,scrollbars=yes,status=no');
}
function OpenWhat (c) {
window.open(c,
'whatsablog',
'width=230,height=335,scrollbars=no,status=no');
}
</script -->