mtde.info

Movable Type Developers Express

サムネイル画像でエントリリスト

2008年2月12日 22:29 | Writer: apstar | 記事本文

サムネイル画像にエントリへのリンクをつけてリスト化を行うサンプルです。エントリリストとして機能します。

以下のような仕様です。

このサンプルコードは、インデックスページ、カテゴリページ、エントリページで使用できますが、場合によっては記事の投稿時に再構築されないエントリが出てきますので、インデックスページにのみ適用するのが無難です。

コード

<MTIf name="main_index">
   <MTSetVarBlock name="CurCat"><MTCategoryLabel></MTSetVarBlock>
<MTElse>
   <MTIf name="category_archive">
      <MTSetVarBlock name="CurCat"><MTCategoryLabel></MTSetVarBlock>
   <MTElse>
      <MTSetVarBlock name="CurCat"><MTEntryCategory></MTSetVarBlock>
   </MTIf>
</MTIf>

<MTIfNonZero tag="AssetCount">
<MTSetvar name="counter" value="0">

<MTEntries lastn="0" category="$CurCat">
   <MTEntryAssets type="image">
      <MTAssetsFooter>
         <MTSetVar name="counter" op="++">
         <MTSetVarBlock name="EntryLink[$counter]"><$MTEntryPermalink$></MTSetVarBlock>
         <MTSetVarBlock name="imagewidth"><$MTAssetProperty property="image_width"$></MTSetVarBlock>
         <MTSetVarBlock name="imageheight"><$MTAssetProperty property="image_height"$></MTSetVarBlock>
         <MTIf name="imagewidth" gt="$imageheight">
            <MTSetVarBlock name="ImageCode[$counter]"><img src="<$MTAssetThumbnailURL height="70"$>" alt="on <$MTAssetProperty property="description"$>:<$MTAssetProperty property="description"$>" title="on <$MTEntryTitle$> : <$MTAssetProperty property="description"$>" /></MTSetVarBlock>
         <MTElse>
            <MTSetVarBlock name="ImageCode[$counter]"><img src="<$MTAssetThumbnailURL width="70"$>" alt="on <$MTAssetProperty property="description"$>:<$MTAssetProperty property="description"$>" title="on <$MTEntryTitle$> : <$MTAssetProperty property="description"$>" /></MTSetVarBlock>
         </MTIf>
      </MTAssetsFooter>
   </MTEntryAssets>
</MTEntries>

<MTIf name="counter" gt="10">
   <MTSetVar name="forcounter" value="10">
<MTElse>
   <MTSetVar name="forcounter" value="$counter">
</MTIf>

<MTIf name="counter" gt="0">
   <dl>
      <dt>Photos</dt>
      <dd>
         <ul>
            <MTFor var="x" from="1" to="$forcounter">
               <li class="item">
                  <a href="<MTGetVar name="EntryLink[$x]">"><MTGetVar name="ImageCode[$x]"></a>
               </li>
            </MTFor>
         </ul>
      </dd>
   </dl>
</MTIf>
</MTIfNonZero>

アイテム関連サンプル

2008 mtde.info