Listing Entries from Multiple Movable Type Blogs, Sorted by Date

| 1 Comment | No TrackBacks
Movable Type has a pretty neat set of features called 'MultiBlog' which allow you to display content on your blog that is coming from other blogs on your installation (aggregation...).  That is all very nice if all you want to do is show a combined list of the most recent entries of (for example) blog 1, 2 and 5 (just do <mt:entries blog_ids="1,2,5">...</mt:entries> and you are done).  But what if you want more control over the entries that are being displayed?
An example
Suppose you want the entries in category "Sports" from one blog, the entries tagged "soccer" and "tennis" from another blog and all entries from a third blog (which is about nothing but baseball anyway).  All ordered by date and just the ten most recent ones please.

It would be nice if you could do <mt:entries blog_ids="1,2,5" categories="1:sports" tags="2:soccer,tennis" lastn="10"> or something similar, but this is not how it works.  Does that mean it is impossible?  Of course not, this is Movable Type!

The solution
Use an <mt:setvarblock> tag to capture enough entries from all three sources in a hash, where the date/time is the value.  Then sort by the value and display the first ten items you get.

<mt:entries blog_ids="1" category="Sports">
<mt:setvarblock name="theentry"><li><mt:entrydate> <mt:entrytitle></li></mt:setvarblock>
<mt:setvarblock name="entries{$theentry}"><mt:entrydate format="%Y%m%d%H%M%S"></mt:setvarblock>
</mt:entries>

<mt:entries blog_ids="2" tag="soccer OR tennis">
<mt:setvarblock name="theentry"><li><mt:entrydate> <mt:entrytitle></li></mt:setvarblock>
<mt:setvarblock name="entries{$theentry}"><mt:entrydate format="%Y%m%d%H%M%S"></mt:setvarblock>
</mt:entries>

<mt:entries blog_ids="5">
<setvarblock name="theentry"><li><mt:entrydate> <mt:entrytitle></li></mt:setvarblock>
<mt:setvarblock name="entries{$theentry}"><mt:entrydate format="%Y%m%d%H%M%S"></mt:setvarblock>
</mt:entries>


<ul>
<mt:loop name="entries" sort_by="value numeric reverse">
<mt:if name="__counter__" lt="11"><mt:var name="__key__"></mt:if>
</mt:loop>
</ul>


No TrackBacks

TrackBack URL: http://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/38

1 Comment

Hi,

I came across this post from google looking for some way to sort entry by title.
I know you can use MTEntries sort_by="title" but this modifier prioritizes capitalized letters first to the sort. Im not sure if this is a glitch in the system but this modifier should sort by alphabets used in the title.

Example:

I would like to sort these titles:
-APRICOT
-Aligator
-ABBEY
-Apple

If MTEntries sort_by="title" is used:
-ABBEY
-APRICOT
-Aligator
-Apple

But it really should be
-ABBEY
-Aligator
-Apple
-APRICOT

Would you know how to this?

Leave a comment