Listing Entries from Multiple Movable Type Blogs, Sorted by Date

| 15 Comments | 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: https://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/38

15 Comments

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?

This was spectacularly useful to me. I'd been giving myself a bit of a headache trying to come up with just this logic. Thank you!

useful to me. I'd been giving myself a bit of a headache trying to come up with just this logic

Thanks for this, took me a while to figure out where to insert everything (which is the main reason I never had a blogroll in the first place, but whatever) but it's working fine now (except that now I need to rebuilt all my old entries.. and unless I do it a few at a time it crashes but that's another problem..)

Thanks for sharing this great tip!

I am facing very stupid problem. I have created a widget 'popular entries' which is being displayed on blog page and blog's categories page. On blog page, it displays 5 entries as expected but on blog's categories page, it just show 1 entry as it seems to be taking context of blog category.

Code is like this,


title -

As the code is common and I have specified multiple blogs as context so why does it show only 1 entry on blog category page. It should show 5 entries there as well.

Am I doing something wrong here?

I totally can't get this to work. For some reason the lt="11" isn't limiting the entries to the last 10 (or any number) at all, and it isn't ordering them by date properly. It's just spitting them out through the loop in the order that they were placed. Any ideas? Thanks.

Nevermind - the reason it won't work is because there's an error in third block of code in the example (which just happened to be the one I grabbed). It's missing the

I used an mt:setvarblock tag in order to capture enough entries from all three sources in a hash, and it works, thank you for your advise

銇傘伨銈娿伀銈傞牷绻併伀銇濄倢銇汉銆呫亴涓夋鍏冦仹銇伩鎬濊�冧笘鐣屻仺銇浉浜掍綔鐢 ニューバランス 靴 ㄣ仺銉愩儵銉炽偣betweens銇仱銇勩仸銇郊銈夈伄鐗╃悊鐨勩仾鑷繁銇ㄥ懆鍥层伄涓栫晫銇銇忋倛銇嗐仹銇檚houlds銇с伅銇椼亱銇椼�佺墿浜嬨亴灏戙仾銇忓績銇泦涓仐銇︺亜銈嬪牬鍚堛伀銇柊銇熴仾銉愩儵銉炽偣銈掗仈鎴愩仚銈嬨亾銇ㄣ�併仢銇椼仸銈堛倞澶氥亸銇績鑷撱伀鍚戙亱銇c仸闆嗕腑銇椼仧銆�,ニューバランス 靴
绉併仧銇°伄绀句細銇腑銇у姏銇儛銉┿兂銈广仺銇椼仸銇�併仢銈屻亴绉併仧銇°伄鎯戞槦銇с亗銈娿�併儠銈с儫銉嬨兂銇ㄣ伄銉愩儵銉炽偣銇搞伄鐢锋�ф敮閰嶃亱銈夎嚜鍒嗐伄銈ㄣ儘銉偖

あまりにも頻繁にそれは人々が三次元でのみ思考世界との相互作用 ニューバランス レディース とバランスbetweensについての彼らの物理的な自己と周囲の世界に行くようですshouldsではしかし、物事が少なく心に集中している場合には新たなバランスを達成すること、そしてより多くの心臓に向かって集中した。
私たちの社会の中で力のバランスとしては、それが私たちの惑星であり、フェミニンとのバランスへの男性支配から自分のエネルギーシフトの中で、私たちの体の中で起こってAUSSI根本的な変化があります。このシフトは、心臓を中心とした多くである1〜心の中心の存在からのものです。
最近まで、私たちは、幅、長さ、高さなど、私たちが知って

Mentionné dans le système de retraite fran? ais, donnant l'i シャネル バッグ激安 mpression que le parti au pouvoir a osé remuer un nid de frelons comme le courage, malgré les difficultés. 14 juin,シャネル バッグ激安, le Comité spécial chargé d'élaborer le système de retraite Xi Moluo (Yannick Moreau) Mme Hérault a présenté un ra

Too frequently it appears many people continue ones own planets thinkin chanel 財布 g about primarily with the last measurements additionally, the sociallizing and even account balance around ones own external selves additionally, the neighboring universe. Though an alternative account balance should really be

I'm sure penning to work with for ones standing for being an English tong Apple MacBook Pro MC374LL/A 13.3-Inch Laptop ue music teacher for which you just presented through Sichuan Day to day. I Cheap Apple iPad 2 64GB just take on inclined need for typically the put up considering that I just discover your leading not to mention things most certainly fulfill the desi

additionally progress on the earth Changhong E22M750DV 21.5 inch 54cm Full HD Edge Lit LED / LCD Combo . Comprehensive industrialization,Changhong Apple iMac MB418LL/A 24-Inch Desktop E22M750DV 21.5 inch 54cm Full HD Edge Lit LED / LCD Combo, that's ignited each of the advantage in addition to establishments most of us delight in currently, has become based on the detailed exploitation on the earth’s he

adidas squash footwear squash footwear adidas Custom NFL Jerseys adidas s

Adidas is probably the top rated sporting producers from the world and so they make a huge selection of equipment and clothing together with an amazing choice of squash sneakers. Among the list of places which have prolonged viewed Adidas in fr

Leave a comment