Neil Turner's Blog

Blogging about technology and randomness since 2002

Getting a list of posts with no category

This was useful to me, so I thought I’d share. I’ve been trying to assign all my entries to categories – while all new entries since May (or thereabouts) were assigned categories when they were published, older entries were not. Over the past few months, when I’ve had the inclination, I’ve been trying to add categories, to posts, but I’m finding it increasingly hard to find entries lacking a category, and there seems to be no way in the MT interface to just show category-less entries.

But, I have a solution, and this is how I did it. If you want to do this yourself, head over to Brad Choate’s site and download the MTIfEmpty plugin and install it, then, create a new index template and copy and paste the following code:

<html>
<head>
<title><$MTBlogName$> - Posts with no category</title>
</head>
<body>
<h1>Posts with no category report</h1>
<ol><MTEntries lastn="1000">
<MTIfEmpty var="EntryCategory">
<li><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> -
<a href="<$MTCGIPath$>mt.cgi?__mode=view&_type=entry&id=<$MTEntryID$>&blog_id=1">[edit]</a></li>
</MTIfEmpty></MTEntries></ol>
</body>
</html>

This will generate a report like this which lets you edit each entry. Once you’ve done a few, rebuild the page and those that you’ve fixed will disappear. To vary on the theme, replace <MTIfEmpty var="EntryCategory"> with <MTIfEmpty var="EntryExcerpt"> to get entries without excerpts, or <MTIfEmpty var="EntryKeywords"> for entries sans keywords. You get the idea.

The plugin, while not sounding very interesting, is actually immensely useful. Thanks Brad!

Update: note to self – escape blocks of HTML before posting code samples. 😮

Comments are closed.