tips and tricks for movable type

dynamic archives by author
January 23, 2005

The ability to provide archive listings by author has been a much requested option for Movable Type. While you can create a separate index template (using the author attribute on MTEntries) for each author, if you have a lot of them, this becomes a pain to manage (not to mention the negative impact on your rebuilds).

The new dynamic publishing feature, which harnesses the power of Smarty, takes us a few steps closer: you only need a single index template, and then you can just pass the appropriate author name as a variable to the page to limit the listing to that author's entries.

Create a new index template named By Author (be sure to enable dynamic building), using the following code:

<ul>
<MTEntries author="`$smarty.request.author`" lastn="9999">
<li><a href="<$MTEntryPermalink valid_html="1"$>"><$MTEntryTitle$></a></li>
</MTEntries>
</ul>

Set the output file path (I used authors/index.php) and save the template.

Then, link to the author-specific listing like this:

<MTBlogURL>authors/index.php?author=girlie

(Replace girlie with your author name, of course.)

You can also generate a listing for all authors with the MTAuthors plugin, but since it's not yet been updated for dynamic publishing, you'll need to use a static page for this. Because commenter names are also stored in the mt_author table now, and some real authors may not have posted any entries yet, I also relied upon the Compare plugin, to make sure the author actually has some entries.

Here's the code for the listing:

<h2>Archives by Author</h2>
<ul>
<MTAuthors>
<MTIfNotEqual a="[MTAuthorEntryCount]" b="0" numeric="1">
<li><a href="<MTLink template="By Author">?author=<MTAuthorName>"><MTAuthorName></a></li>
</MTIfNotEqual>
</MTAuthors>
</ul>

Replace By Author with the name of the first template you created, to automatically generate the proper link for that template's output file.

If your Main Index Template is published dynamically (and you want to keep it that way), use a separate static index template for the author listing, and then just include the output file in your Main Index Template:

<?php ("/full/path/to/included/file/authors.inc"); ?>

Props to Brad once again - although the questions I asked him weren't for this purpose, his patient explanations are always so informative that I can't help but be inspired!

Comments

Ooh that's pretty cool using Smarty. I really need to read the Smarty manual to see what cool things can be done with it!

by Arvind [TypeKey Profile Page] | 01.24.05 03:10 AM

Girlie,
Thank you for explaining the author archiving method. I've just gotten started with my first blog for my fiancee and I and this bit of code will be a nice little perk for family...

Many thanks from a newly made fan,
Paul

by Paul [TypeKey Profile Page] | 03.13.05 07:13 PM

Wow I must have stared at this page for 2 days until I finally figured out how to implement the solution it provided me. I am dense!! Thanks so much for providing this code!!!

by Matt Waters | 12.14.05 02:57 PM

This is awesome! Just one thing: The list of posts generated by the author page doesn't link to the posts themselves. The list of post titles shows up great, but those titles all share the link to the author's individual page (the URL of the page the list appears on, actually) rather than going to the individual post. I used the exact code you gave in this great tutorial. Is there any trick I might try?

 Here's an example of what I'm talking about. All of the links on that page are the same. Any suggestions on how I can make them point to the individual posts?

 Thanks!

by toddc | 12.15.05 11:22 PM

When you say, author=girlie, which MT field is that - username or display name?

Also, how are capitalization and spaces in the names handled?

by Kevin Aylward | 12.27.05 04:04 PM

Blimey - this looks cool, naturally I can't get it to work. How do I know if I have smarty?

If I just copy and past the first code exactly as described, and I check "Enable dynamic building for this template" then try and enter the URL, there's nothing there:

link

So.... does this mean I'm missing smarty? Or do I have to build the thing somehow initially? There is obviously no such file as test.php so that URL naturally fails.

Drat... I'm totally stumped!

by Nick | 02.03.06 08:16 PM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 0
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/211)