a links database with MT
Inspired by recent articles on how to use Movable Type for more than just blogs, I’ve been trying this out on more areas of the site. The news, articles and album cover playlist sections are MT powered, and now the links database is too. This means I can now add content to the site from either the web or from my weblog editor in NetNewsWire.
The technique has been well documented on many blogs, (wholelottanothing’s is very well written) so I’ll skimp a bit. First I created a new blog called ‘links’ and removed templates I wouldn’t need (such as the stylesheets and individual entry archives). I also set archiving to ‘category’ and turned comments and convert line breaks off. Then I decided which MT tags to use for which piece of data:
- MTCategories – the link category
- MTEntryTitle - Website name
- MTEntryKeywords - the URL
- MTEntryBody – site description
I inserted these tags into the main MT Template:
<MTCategories> <h3><$MTCategoryLabel$> (<$MTCategoryCount$>)</h3> <MTEntries lastn="100" sort_by="title" sort_order="ascend"> <p><a href="<$MTEntryKeywords$>" title="visit <$MTEntryTitle$>"> <$MTEntryTitle$></a> // <$MTEntryBody$></p> </MTEntries> </MTCategories>
This then creates a page, listing all the links within their categories. The tags in the category archives page (where just one category of links is shown) needs to be slightly different:
<h3><$MTArchiveTitle$> (<$MTArchiveCount$>)</h3> <MTEntries lastn="100" sort_by="title" sort_order="ascend"> <p><a href="<$MTEntryKeywords$>" title="visit <$MTEntryTitle$>"> <$MTEntryTitle$></a> // <$MTEntryBody$></p> </MTEntries>
To get the links to display in alphabetical order, add sort_by=“title” sort_order=“ascend” to the MTEntries tag. I used
tags to list each link – you may prefer an unordered list. ‘MTCategoryCount’ shows the number of entries in that category. To make adding links easier, you can customise the ‘new entry’ form in MT, so that it only shows the fields you want to use – Title, Category, Entry Body and Keywords. The last thing I needed to do was create the list of link categories for the main menu. I created a new index template called ‘droplinks.php’ in the links blog, which just contained the following:
<MTCategories> <li> <a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryLabel$> links"> <$MTCategoryLabel$> (<$MTCategoryCount$>)</a> </li> </MTCategories>
This is then called up an include in the main navigation under ‘destinations’. Job done.
Next – how to build your own house and landscaped garden using MT…