23 Dec 03

How to get aggregate category and monthly archives in Movable Type for multiple weblogs

Today I sat myself down in front of the computer with the goal of combining the monthly archives and category archives for my two weblogs, and without getting up until I finished. It took a while, but I finally managed it. Since I couldn't find any sites on how to specifically do this (or any implementations of it, though I simply may not have been able to find any) I figured it would be helpful to give a little tutorial on how to combine the category archives and monthly archives for multiple blogs.

First of all you're going to need to grab Brad Choate's MTSQL plugin and Kevin Shay's Compare plugin. To avoid repeating what has already been said elsewhere, I refer you to this very useful tutorial on how to get multiple weblogs with different formats to display on the same index page. However, it took some effort to get the <ul> tags to wrap correctly, so for the benefit of anyone else trying to wrap something around chunks of specific post formats (a <hr> or <ul> tag for instance, as you also see on kottke's weblog) here is the relevant MT markup I used in my index template:

<?php $ulvar = "0"; ?>
<MTSQLEntries query="select entry_id, entry_blog_id from mt_entry where entry_blog_id in (2,4) and entry_status=2 order by entry_created_on desc limit 0,140" unfiltered="1">
<$MTEntryTrackbackData$>
<MTDateHeader>
<?php if ($ulvar == "1") { echo("</ul>"); $ulvar = "0"; } ?>
<h3 class="date">
<$MTEntryDate format="%x"$>
</h3>
</MTDateHeader>

<MTIfEqual a="[MTSQLColumn column='2']" b="4">
<?php if ($ulvar == '0') { echo('<ul class="linkies">'); $ulvar = "1"; } ?>
<li><$MTEntryBody$>
<span class="cmt">
<MTEntryIfAllowComments><a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>" onclick="
OpenComments(this.href); return false">(<$MTEntryCommentCount$>)</a>
</MTEntryIfAllowComments>
</span></li>
</MTIfEqual>

<MTIfEqual a="[MTSQLColumn column='2']" b="2">
<?php if ($ulvar == "1") { echo("</ul>"); $ulvar = "0"; } ?>

<div class="blogbody">
<a name="<$MTEntryID pad="1"$>"></a>

<h3 class="title"><$MTEntryTitle$></h3>

<$MTEntryBody$>

<MTEntryIfExtended>
<span class="extended"><a href="<$MTEntryPermalink$>#more">Continue reading "
<$MTEntryTitle$>"</a></span><br />
</MTEntryIfExtended>

<div class="posted">Posted to <a href="<$MTArchiveLink archive_type="Category"$>"><$MTEntryCategory$></a> @ <a href="<$MTEntryPermalink$>"><$MTEntryDate format="%X"$></a>

<MTEntryIfAllowComments>
| <a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>" onclick="

OpenComments(this.href); return false">Comments (<$MTEntryCommentCount$>)</a>
</MTEntryIfAllowComments>

<MTEntryIfAllowPings>
| <a href="<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=

<$MTEntryID$>" onclick="OpenTrackback(this.href); return false">TrackBack (

<$MTEntryTrackbackCount$>)</a>
</MTEntryIfAllowPings>

</div>

</div>
</MTIfEqual>

</MTSQLEntries>

Alright, now onto how I got the date archives to be combined (note, if you've gotten this far, and the above doesn't make any sense, read the aforementioned tutorial which I will link again here). Combining the entries from my linkies weblog and my regular weblog into date-based archives was actually pretty easy, I just had to look up some mySQL commands to figure out how to format it correctly, anyway, here is the relevant MT markup for the date-based archives:

<MTSQLEntries query="select entry_id, entry_blog_id from mt_entry where entry_blog_id in (2,4) and entry_status=2 and DATE_FORMAT(entry_created_on, '%M %Y')='[MTArchiveTitle]' order by entry_created_on desc" unfiltered="1">

The markup for the categories is a bit more complicated, but you don't really need to understand any of it past the entry_status=2 (Note: this template must be applied to the category-templates for all weblogs you are combining):

<MTSQLEntries query="select entry_id, entry_blog_id from mt_entry, mt_placement, mt_category where entry_blog_id in (2,4) and entry_status=2 and placement_entry_id=entry_id and placement_blog_id=entry_blog_id and category_label='[MTArchiveTitle]' and category_id=placement_category_id and category_blog_id=placement_blog_id order by entry_created_on desc" unfiltered="1">

And then if you want a category listing on the side, here's the code for that which combines the categories of all the weblogs you want included. I haven't figured out how to get the number of entries for each comment included in the code, and I doubt this is possible, but hopefully someone will prove me wrong.

<MTSQLCategories query="SELECT DISTINCT category_id FROM mt_category, 
mt_placement, mt_entry WHERE (placement_category_id = category_id)
AND (placement_entry_id = entry_id) AND (entry_status = 2) GROUP BY category_label ORDER BY category_label" unfiltered="1">
<a href="<MTArchiveLink>">
<$MTCategoryLabel$>
</a><br>
</MTSQLCategories>

And that's that. I hope this tutorial comes in handy to someone. If you have any questions, just post it in the comments, I check for comments every day so I'll probably respond within 24 hours.


Post a comment









Remember personal info?





Type the characters you see in the picture above.