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

| コメント(0) | トラックバック(0)

サイドバーに最新記事から、各エントリから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" を指定するのは、一番代表的な画像(エントリで最初の画像)を表示させるためです。

トラックバック(0)

トラックバックURL: http://www.shikidahironori.jp/mt/toraxtukubaxtukuspam.cgi/792

コメントする

このブログ記事について

このページは、しきだ博紀が2009年10月30日 01:18に書いたブログ記事です。

ひとつ前のブログ記事は「MT4iと連携した携帯サイトの構築」です。

次のブログ記事は「Perl版ダイナミック・パブリッシング(MT4.2用)」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

Twitter Updates

OpenID対応しています OpenIDについて
Powered by Movable Type 4.27-ja