ブログから親ウェブサイトのURL, ID, サイト名を取得するコードメモ
<mt:BlogParentWebsite> <$mt:WebsiteURL setvar="siteUrl"$> <$mt:WebsiteID setvar="siteId"$> <$mt:WebsiteName setvar="siteName"$> </mt:BlogParentWebsite> <p>[確認用]siteUrl=<$mt:Var name="siteUrl"></p>
<!-- set [this_content] --> <mt:SetVarBlock name="this_content"> <mt:Pages tag="@home" lastn="1"> <h1 id="page-title"><$mt:PageTitle$></h1> <$mt:PageBody$> </mt:Pages> </mt:SetVarBlock>
↓と書く替わりに、こう書く↓
<!-- set [this_content] --> <mt:Pages tag="@home" lastn="1" setvar="this_content"> <h1 id="page-title"><$mt:PageTitle$></h1> <$mt:PageBody$> </mt:Pages>
→setvar
http://www.movabletype.jp/documentation/appendices/modifiers/setvar.html
<!-- set [body_id], [is_sidebar], [this_title], [site_id] --> <$mt:SetVar name="body_id" value="home"$> <$mt:SetVar name="is_sidebar" value="yes"$> <$mt:SetVar name="this_title" value="HOME"$> <mt:SetVarBlock name="site_id"><$mt:WebsiteID$></mt:SetVarBlock>
と書く替わりに、
<!-- set [body_id], [is_sidebar], [this_title], [site_id] --> <mt:SetVars> body_id=home is_sidebar=yes this_title=HOME site_id=<$mt:WebsiteID$> </mt:SetVars>
→複数の変数をまとめて設定できる MTSetVars タグ
http://www.movabletype.jp/blog/mtsetvars.html
→MTSetVars
http://www.movabletype.jp/documentation/appendices/tags/setvars.html<!– set [body_id], [is_sidebar], [this_title], [site_id] –>
MT5におけるウェブサイトと、配下のブログの関係をボチボチお勉強
Website-A ├Blog-A1 └Blog-A2
こんな構成になっているとしたとき、
<mt:BlogParentWebsite> <$mt:WebsiteID setvar="website_id"$> </mt:BlogParentWebsite> <$mt:Include module="※モジュール名※" blog_id="$website_id"$> [確認用]website_id: <$mt:GetVar name="website_id"$>
BlogA-1のテンプレ
1. 子ブログ内でいきなりmt:WebsiteID:<$mt:WebsiteID$><br />
<mt:BlogParentWebsite><$mt:WebsiteID setvar="website_id">
2. 子ブログ内mtBlogParentWebsiteブロックタグの中でMTWebsiteID: <$mt:WebsiteID$><br />
3. 子ブログ内mtBlogParentWebsiteブロックタグの中で親サイトのテンプレートモジュール呼び出し
(その中でmt:WebsiteID):<$mt:Include module="WS-module" blog_id="$website_id"$><br />
</mt:BlogParentWebsite>
4. 子ブログ内mtBlogParentWebsiteブロックタグの外で親サイトのテンプレートモジュール呼び出し(その中でmt:WebsiteID):
<$mt:Include module="WS-module" blog_id="$website_id"$><br />
Website-A内のテンプレートモジュール(WS-module)
<$mt:WebsiteID$>
結果
1.子ブログ内でいきなりmt:WebsiteID:0 -> NG 2. 子ブログ内mtBlogParentWebsiteブロックタグの中でMTWebsiteID: 1 -> OK 3. 子ブログ内mtBlogParentWebsiteブロックタグの中で親サイトのテンプレートモジュール呼び出し (その中でmt:WebsiteID):1 -> OK 4. 子ブログ内mtBlogParentWebsiteブロックタグの外で親サイトのテンプレートモジュール呼び出し (その中でmt:WebsiteID):0 -> NG