Movable Type blogroll.

Movable Type continues to impress me with its flexibility and power. Last week I decided I’d had it up to here with maintaining the list of links that appears on the right side of my home page (the “blogroll,” as some people call it). Instead of manually editing HTML code in my weblog template, why not use MT to auto-generate a list of links, then use PHP to include this link list anywhere I needed it? Better still: MT’s categories feature would make it easy to group related links together.

You can see the results of this solution in my new “RESOURCES” list, on the right side of the Tweney Report home page.

Other people have probably found this solution themselves, but I’m posting it here in case it’s useful to anyone else.

How it works: I set up a new weblog called “quicklinks.” I entered each link into this new weblog as an entry, using MT’s fields as follows:

Title — the link’s title
Entry Body — the main URL for that link
Extended Entry — the corresponding RSS feed, if I could find it
Excerpt — a short, optional summary

I also assigned a category to each link: tech news, tech blogs, bookish sites, search tools, and so forth.

Then I created a new index template with the filename include.html. Here’s the complete code of that template:


<MTCategories>
<strong><$MTCategoryLabel$></strong>
<MTEntries sort_by=”title” sort_order=”ascend”>
<MTEntriesHeader>
<ul>
</MTEntriesHeader>
<li><a title=”<$MTEntryExcerpt$>” href=”<$MTEntryBody convert_breaks=”0″$>”><$MTEntryTitle$></a><MTEntryIfExtended> | <a title=”XML-RSS feed” href=”<$MTEntryMore convert_breaks=”0″$>”>RSS</a></MTEntryIfExtended></li>
<MTEntriesFooter>
</ul>
</MTEntriesFooter>
</MTEntries>
</MTCategories>

What this template does is spit out all of the “Quicklinks” entries, grouped by category, and ordered alphabetically within each category. Each entry appears as its name, hyperlinked to the main URL, with a link title that shows the site summary, if I entered one. If I entered a URL for the RSS feed, that shows up as an additional link. (Note: Entries that aren’t assigned to any category at all won’t show up in this list, and entries that are assigned to multiple categories should show up under each category they’ve been assigned to.)

I then published the Quicklinks blog and went back to my main weblog, the Tweney Report. Here I entered the following snippet of code into my main index template (a PHP file):


<?php include(“http://dylan.tweney.com/links/include.html”); ?>

This line uses PHP to bring in the “include.html” file created by the quicklinks blog.

Voilá! Instant blogroll. From now on, I can add, remove, or edit links using MT’s standard editing interface, and I don’t have to muck around in templates any more.

Note: Rick Klau has done something similar, using the <$MTInclude$> function and a pop-up bookmarklet.

Movable Type blogroll.

11 thoughts on “Movable Type blogroll.

  1. Like the idea but one thing on security;

    If include.html contains any PHP, the remote site reading your URL will *execute* it. Kind of a dangerous situation…

    Perhaps better would be on the remote site;

    PHP 4.3.0+
    echo ( file_get_contents(“http://dylan.tweney.com/links/include.html”) );

    PHP < 4.3.0

    echo ( implode(”,file(“http://dylan.tweney.com/links/include.html”)) );

  2. Cool idea! I’ve been playing with something similar for a photoblog template (using some of the additional fields for file names etc..)

    Well done 🙂

    Next; using your setup below and generating PHP blogroll(s) sorted by updates (see: http://www.philringnalda.com/phpblogroll/ for more inspiration 🙂

  3. Wow.. such a great idea! I think I will have to incorporate something like this into my own weblog! Thanks for sharing!

  4. As soon as I read your article, I just had to add this functionality to my site. I don’t have the categorization established yet, but that will be up soon. Thanks for taking the time to write up such an informative article!

  5. Harry, your comment about security is apt, and if anyone is thinking of pulling a links file from someone else’s site (like mine) you should definitely follow his advice. However, since I’m pulling the file from my own site, I have control over that HTML file that’s getting included. Perhaps I should have written that PHP code thus:

    include(“links/include.html”);

    Anders, I like the idea of using data from weblogs.com to figure out which weblogs on the list were most recently updated. Clever!

    Thanks to the rest of you for your comments!

  6. Not only is MT a good tool, Dylan, but it makes it quite easy to have more than one weblog on the same code base. I have four running off a single MT installation: http://www.intuitive.com/blog/ is my main weblog (The Intuitive Life), but I also run http://booktalk.intuitive.com/ my booktalk weblog, http://www.APparenting.com/ for attachment parenting (half-unbuilt, but still quite busy!) and a private password-only weblog for an entrepreneurial group I’m in…

    Oh, and HI Dylan! Long time, my friend….

  7. Thanks for this wonderful articles and thanks to all those who added valuable comments.

    Using the php feature obliges you to turn your MT pages into php format with .php extention. Useful information for this is visible at http://www.virtualvenus.org/wiki/view/MT/ConvertingToPHP.

    The MTOtherBlog plugin is great and avoids the use of php, but it is not dynamic. You need to rebuild each time you want your MT site to integrate new links from the other MT site.

  8. Jean-François, that is true. It doesn’t update automatically, but I do have a hourly cron job that rebuilds my blog. I originally set it up so that I could could my pages related to all the blogs on the site up to date ( http://people.etango.com/ ). It has the nice side effect of allowing me to use MTOtherBlog without thinking too much (or manually rebuilding too much).

Comments are closed.