TopMovable Typeカスタムフィールド > 特定のカスタムフィールドの情報を出力する
2010年4月16日

特定のカスタムフィールドの情報を出力する

Posted at April 16,2010 12:30 AM
Category:[カスタムフィールド]
Tag:[, ]

Movable Typeで特定のカスタムフィールドの情報を出力するためのカスタマイズを紹介します。

ここではブログ記事に複数追加したカスタムフィールドから、次のように定義した「価格」カスタムフィールドの名前と値を出力する例で説明します。

  • テンプレートタグ名:MTEntryProductPrice
  • ベースネーム:cf_1

1.基本

あるシステムオブジェクト(ここではブログ記事)に複数のカスタムフィールドの情報を出力するには、MTEntryCustomFieldsタグを利用し、タグブロック内でMTCustomFieldXXタグを記述します。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:CustomFieldName />
    <mt:CustomFieldValue />
  </mt:EntryCustomFields>
</mt:Entries>

ただし、この場合、ブログ記事に登録されているすべてのカスタムフィールドの情報が出力されてしまいます。

2.特定のカスタムフィールドの情報を出力する

特定のカスタムフィールドの情報を出力するには、MTEntryCustomFieldsタグブロック内で、MTIfタグを使ってMTCustomFieldBasenameタグを判定する方法があります。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:If tag="CustomFieldBasename" eq="cf_1">
      <mt:CustomFieldName />
      <mt:CustomFieldValue />
    </mt:If>
  </mt:EntryCustomFields>
</mt:Entries>

MTCustomFieldValueタグは、MTEntryProductPriceタグでもOKです。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:If tag="CustomFieldBasename" eq="cf_1">
      <mt:CustomFieldName />
      <mt:MTEntryProductPrice />
    </mt:If>
  </mt:EntryCustomFields>
</mt:Entries>

もう少しきちんと書くのであれば、MTEntryProductPriceタグの値があることも判定します。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:If tag="CustomFieldBasename" eq="cf_1">
      <mt:If tag="EntryProductPrice">
        <mt:CustomFieldName />
        <mt:MTEntryProductPrice />
      </mt:If>
    </mt:If>
  </mt:EntryCustomFields>
</mt:Entries>

CustomFieldExtensionTags プラグイン」を利用すれば、テンプレートタグ名でも判定できるようになります。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:If tag="CustomFieldTag" eq="EntryProductPrice">
      <mt:If tag="EntryProductPrice">
        <mt:CustomFieldName />
        <mt:MTEntryProductPrice />
      </mt:If>
    </mt:If>
  </mt:EntryCustomFields>
</mt:Entries>

3.失敗例

次のように、カスタムフィールドのテンプレートタグを判定する方法ではうまくいきません。

<mt:Entries>
  <mt:EntryCustomFields>
    <mt:If tag="EntryProductPrice">
      <mt:CustomFieldName />
      <mt:CustomFieldValue />
    </mt:If>
  </mt:EntryCustomFields>
</mt:Entries>
Posted by yujiro   このページの先頭に戻る
関連記事
この記事を読んだ人はこんな記事も読んでいます
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL


コメントする
greeting

*必須

*必須(非表示)


ご質問のコメントの回答については、内容あるいは多忙の場合、1週間以上かかる場合があります。また、すべてのご質問にはお答えできない可能性があります。予めご了承ください。

太字 イタリック アンダーライン ハイパーリンク 引用
[サインインしない場合はここにCAPTCHAを表示します]

コメント投稿後にScript Errorや500エラーが表示された場合は、すぐに再送信せず、ブラウザの「戻る」ボタンで一旦エントリーのページに戻り(プレビュー画面で投稿した場合は、投稿内容をマウスコピーしてからエントリーのページに戻り)、ブラウザをリロードして投稿コメントが反映されていることを確認してください。

コメント欄に(X)HTMLタグやMTタグを記述される場合、「<」は「&lt;」、「>」は「&gt;」と入力してください。例えば「<$MTBlogURL$>」は「&lt;$MTBlogURL$&gt;」となります(全て半角文字)

Now loading...
Introduction
Entries of this Category
Recent Entries
Recent Comments
Recent Trackbacks
QRcode

現在停止中です
携帯電話からこのQRcodeを撮影することで携帯用URLを取得することができます

URI for cellular phones
ギターに入った猫
Styles
Font Size
Default
For defective color vision
Gray Scale
RGB Color
Search this site

このブログをメールで購読する by:FeedBurner

loading ...
Categories
Monthly Archives
BlogPeople
Syndicate this site
FeedBurner(RSS1.0/RSS2.0/Atom)
Counter
これまでのアクセス
クリエイティブ・コモンズ・ライセンス
Powered by
Movable Type 5.12