Movable Type 7.9.5のRainierで記事中の最初の画像をサムネイル画像にする

  • 投稿日:
  • by
  • カテゴリ:

いままで気にしていなかったというか気が付いていなかったのですが、記事の中の一番最後の画像がサムネイル画像として使われていました。

一年前ほど前にMovable Type 7.9.5にアップデートしてからタグの動きが変わったのか…と思いましたが、バージョンアップする前はベースのMovable Typeをかなりいじくりまわしていたので、サムネイル画像なんかそもそも作られていなかったのだと思います。もしくはRainier固有の事情か。

なんとなく一番初めの画像をサムネイル画像にしたかったのでいろいろ調べていたところ、こちらの記事にたどりつきました。

mt:EntryAssetsで記事のアセットの中で一番最初にアップロードされた画像を選択する

こちらの記事とウチでは事情が違うのですが、ヒントになりました。

MTEntryAssetsタグにパラメータ(モディファイア?)を与えることによってなんとかなりそうです。

修正するのはアーカイブテンプレートの「記事」だけで良さそうです。修正する箇所はmeta property="og:image"とlink itemprop="image"のMTEntryAssetsタグのところです。

現状のコードは、

<meta property="og:image" content="
  <mt:EntryAssets type="image" limit="1">
      <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
      <mt:Else>
    <mt:Assets type="image" tag="@SITE_ICON" limit="1">
      <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
      <mt:Else>
    <$mt:SupportDirectoryURL with_domain="1" encode_html="1"$>theme_static/rainier/img/siteicon-sample.png
    </mt:Assets>
   </mt:EntryAssets>">


<link itemprop="image" href="
  <mt:EntryAssets type="image" limit="1">
    <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
    <mt:Else>
    <mt:Assets type="image" tag="@SITE_ICON" limit="1">
    <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
    <mt:Else>
    <$mt:SupportDirectoryURL with_domain="1" encode_html="1"$>theme_static/rainier/img/siteicon-sample.png
      </mt:Assets>
  </mt:EntryAssets>">

となっていますが、MTEntryAssetsタグにsort_order="ascend"を追加します。


<meta property="og:image" content="
  <mt:EntryAssets type="image" limit="1" sort_order="ascend">
      <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
      <mt:Else>
    <mt:Assets type="image" tag="@SITE_ICON" limit="1">
      <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
      <mt:Else>
    <$mt:SupportDirectoryURL with_domain="1" encode_html="1"$>theme_static/rainier/img/siteicon-sample.png
    </mt:Assets>
  </mt:EntryAssets>">


<link itemprop="image" href="
  <mt:EntryAssets type="image" limit="1" sort_order="ascend">
    <$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
    <mt:Else>
    <mt:Assets type="image" tag="@SITE_ICON" limit="1"><$mt:AssetThumbnailURL height="320" square="1" encode_html="1"$>
    <mt:Else>
    <$mt:SupportDirectoryURL with_domain="1" encode_html="1"$>theme_static/rainier/img/siteicon-sample.png
      </mt:Assets>
  </mt:EntryAssets>">

一応Movable TypeのTemplate Tag Referenceも確認しましたがイマイチ理解できず。

たぶん意図的にソートを指定しないデフォルトの動きは、sort_order="descend"なのだと思います。

とりま意図したとおりにサムネイル画像が設定されたので良しとします。