6.22 ブログ記事ページのデザインをカテゴリ別に切り替える

P.489

ブログ記事に設定したカテゴリを利用して、レイアウトを切り替える

●ブログ記事テンプレートの修正

<mt:entryCategory setvar="entry_category" />
<mt:if name="entry_category" like="お知らせ|イベント">
  <mt:include module="$entry_category"$>
<mt:else>
  <mt:include module="デフォルトブログ記事"$>
</mt:if>

P.490

●「お知らせ」ブログ記事用テンプレートモジュールの作成

テンプレート名:お知らせ
テンプレートの内容:次の内容を設定

<mt:setVars>
title=<mt:entryTitle encode_html="1" />: <mt:blogName encode_html="1" />
body_onload=mtEntryOnLoad()
page_layout=layout-two-column-right
</mt:setVars>
<mt:include module="ヘッダー" />
<div id="contents" class="clearfix">
  <div id="main">
    <div class="content-nav">
    <mt:entryPrevious>
      <a href="<mt:entryLink archive_type="Individual" />">&laquo; <mt:entryTitle encode_html="1" /></a> |
    </mt:entryPrevious>
      <a href="<mt:link template="main_index" />">メインページ</a> |
      <a href="<mt:link template="archive_index" />">アーカイブ</a>
    <mt:entryNext>
      | <a href="<mt:entryLink archive_type="Individual" />"><mt:entryTitle encode_html="1" /> &raquo;</a>
    </mt:entryNext>
    </div>
    <div class="content">
      <h2 class="entry-header"><mt:entryTitle encode_html="1" /></h2>
      <mt:include module="メタデータ" />
      <div class="entry-content clearfix">
        <mt:if tag="entryBody">
        <div class="entry-body"><mt:entryBody /></div>
        </mt:if>
        <mt:if tag="entryMore">
        <div id="more" class="entry-more"><mt:entryMore /></div>
        </mt:if>
      </div>
      <mt:include module="コミュニケーション" />
    </div>
    <mt:include module="トラックバック" />
    <mt:include module="コメント" />
  </div>
  <div id="sub1">
    <mt:include module="サイドバー左" />
    <mt:include module="サイドバー右" />
  </div>
</div>
<mt:include module="フッター" />
<body class="layout-two-column-right" />

P.491

●「イベント」ブログ記事用テンプレートモジュールの作成

テンプレート名:イベント
テンプレートの内容:「お知らせ」テンプレートの内容を設定して、004のみ、次の内容に変更

<mt:setVars>
title=<mt:entryTitle encode_html="1" />: <mt:blogName encode_html="1" />
body_onload=mtEntryOnLoad()
page_layout=layout-two-column-left
</mt:setVars>
...後略...
<body class="layout-two-column-left" />

他の情報でブログ記事ページのデザインを切り替える

「ブログ記事」アーカイブテンプレート

<mt:entryExcerpt no_generate="1" setvar="entry_excerpt" />
<mt:if name="entry_excerpt" like="お知らせ|イベント">
  <mt:include module="$entry_excerpt"$>
<mt:else>
  <mt:include module="デフォルトブログ記事"$>
</mt:if>

P.492

その他のカテゴリ判定方法

●デフォルトカテゴリがない場合

「ブログ記事」アーカイブテンプレート

<mt:entryIfCategory name="デザイン">
  <mt:include module="デザインカテゴリ" />
</mt:entryIfCategory>
<mt:entryIfCategory name="お知らせ">
  <mt:include module="お知らせカテゴリ" />
</mt:entryIfCategory>

●デフォルトカテゴリがある場合

「ブログ記事」アーカイブテンプレート

<mt:entryIfCategory name="デザイン">
  <mt:include module="デザインカテゴリ" />
<mt:else>
  <mt:entryIfCategory name="お知らせ">
    <mt:include module="お知らせカテゴリ" />
  <mt:else>
    <mt:include module="デフォルトカテゴリ" />
  </mt:entryIfCategory>
</mt:entryIfCategory>

ウェブページ

Powered by Movable Type 4.261

このアーカイブについて

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