Displaying the Latest from the Blogs that Most Recently Published an Entry with Movable Type

| No Comments | No TrackBacks |
Using Movable Type's Multiblog feature it is relatively easy to aggregate the most recent blog posts accross your entire Movable Type installation. For example, <mt:entries include_blogs="all">...</mt:entries> will get you the ten most recent entries. But sometimes this is not what you need.  What if you want to make sure there is at least one entry from each blog being displayed? 
With the example above, you could theoretically end up with ten entries from the same blog (if it has a much higher posting volume than the other blogs on your installation).  You could try this instead, perhaps:

<mt:multiblog include_blogs="all">
<mt:entries lastn="1">...</mt:entries>

This will get you the most recent entry from each blog on your installation.  But this might still not be what you really need.  What if you have dozens or hundreds of blogs?  You would get a huge list of entries.  And they would  not be sorted in any meaningful order at all.  What if you just wanted the latest entry of each of the ten blogs that most recently published something?  Impossible?  Not at all:

<mt:multiblog include_blogs="all">
<mt:entries lastn="1">
  <mt:entrydate format="%Y%m%d%H%M%S"  var="thedate">
  <mt:setvarblock name="theentry{$thedate}">...</mt:setvarblock>

<mt:loop name="theentry" sort_by="key numeric reverse">
<mt:unless name="__counter__" gt="10"><mt:var name="__value__"></mt:unless>

This section will take the most recent entry of every blog and put it in a hash, with the entry publication date/time in a numeric format as the key.  Finally, the hash is sorted in reverse by key  and the first ten items are displayed.  Voila, the latest entry from each of the ten blogs that most recently published something...

No TrackBacks

TrackBack URL: https://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/5

Leave a comment