エントリーから1つのアイテムだけをサムネイルに表示

サイドバーに最新記事から、各エントリから1づつアイテム(画像)を選んで、並べて表示するTips。

次のテンプレートでは、エントリに複数の画像がある場合、表示されるアイテムが指定した枚数になりません。

<div class="section">
<h2>ブログフォト</h2>
<ul class="photo_widget">
<mt:Entries lastn="6">
<mt:EntryAssets type="image">
<li><a href="<$mt:EntryPermalink$>" title="<$mt:EntryTitle encode_html="1"$>(<$mt:EntryDate format="%b月%e日"$>)"><img src="<$mt:AssetThumbnailURL height="60"$>" alt="<$mt:EntryTitle encode_html="1"$> (<$mt:EntryDate format="%b月%e日"$>)" /></a></li>
</mt:EntryAssets>
</mt:Entries>
</ul>
</div>

そこで、

<mt:IfNonZero tag="AssetCount">
<$mt:setvar name="counter" value="0"$>
<h2>ブログフォト</h2>
<ul>
<mt:Entries lastn="0">
<mt:EntryAssets type="image" lastn="1" sort_order="ascend">
<mt:If name="counter" lt="6">
<$mt:setvar name="counter" op="++"$>
<li><a href="<$mt:EntryPermalink$>" title="<$mt:EntryTitle encode_html="1"$>(<$mt:EntryDate format="%b月%e日"$>)"><img src="<$mt:AssetThumbnailURL height="60"$>" alt="<$mt:EntryTitle encode_html="1"$> (<$mt:EntryDate format="%b月%e日"$>)" /></a></li>
</mt:If>
</mt:EntryAssets>
</mt:Entries>
</ul>
</mt:IfNonZero>

として、指定した枚数を表示させています。

mt:EntryAssets タグに、 sort_order="ascend" を指定するのは、一番代表的な画像(エントリで最初の画像)を表示させるためです。