Rough Drafts

Movable Type blogroll.

How to use Movable Type and PHP to manage a list of links automatically.
Dylan Tweney 2 min read

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(“https://dylan.tweney.com/links/include.html”); ?>

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

Voil

Share
Comments
More from Dylan Tweney - Storylines
Rough Drafts

Fifth Sun

Fifth Sun: A New History of the Aztecs by Camilla Townsend Camilla Townsend has pulled off a remarkable magic trick in this book, reconstituting the Mexica empire with an amazing level of detail and sensitivity. It makes the Aztecs feel like a real people, with a vibrant and complex culture, instead
Dylan Tweney 1 min read

Storylines

Subscribe to my newsletter on writing & storytelling

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Dylan Tweney - Storylines.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.