March 30, 2005
着せ替えMovable Type
- sonots
- 07:56 PM
- コメント (5)
- トラックバック (18)
- カテゴリー:DynamicPublishing
出力ファイルをphpにする、またはダイナミックパブリッシングを利用すれば 動的ページが作れるので、 訪問者がテンプレートを着せ替えられるシステムを導入できます。
css の着せ替えではなく、テンプレートの着せ替えです。
プラグインを使用しているわけではないので、面倒くさいかもしれませんし、楽かもしれません。 サンプルはこの blog のトップへ。
基本となるアイデアは ダイナミックパブリッシングとphp拡張子の差異 で得ることができます。
1. phpへ移行しよう
phpへの移行がすんでいない方は
ダイナミックパブリッシングとphp拡張子の差異
のまえがきを見て、
Main Index, Individual Entry Archive, Date-Based Archive, Category Archive テンプレートを移行してください。
php拡張子移行の場合は、Main Index はテンプレート管理画面で、他の3つのArchive テンプレートが吐き出すファイルはウェブログ設定のほうで変更します。
ダイナミックパブリッシング移行の場合はテンプレート管理画面で、「テンプレート毎に個別に選択」をチェックし、それぞれのテンプレートで、ダイナミックパブリッシングをするように選択してください。
ここではそれらの事前準備が済んでいるものとして話を進めるので php への移行に関してこれ以上の説明はしません。
2. テンプレートモジュールを使おう
現存のテンプレートをテンプレートモジュールに移しておきます。メインのテンプレートにはただの切り替え処理を行わせ、本処理はテンプレートモジュールでさせるとクールかと思います。
Template 管理ページの下のほうにあるテンプレートモジュール(Template Modules) で新しいモジュールを例えば、「DefaultMainIndex」とでも名づけて Main Index テンプレートの内容をコピーしてください。
他のテンプレートも同様に移行します。
Main Index → DefaultMainIndex
Category Archive → DefaultCategoryArchive
Date-Based Archive → DefaultDate-BasedArchive
Individual Entry Archive → DefaultIndividualEntryArchive
と移行したとします。
3. 切り替えPHPテンプレートを作ろう
php 拡張子の場合は、Main Index の内容を
<?php
$MTBlogURL = "<MTBlogURL>";
$url = parse_url($MTBlogURL);
$path = $url['path'];
if($theme = $_GET['theme']) {setcookie('theme', $theme, 0, $path);}
else if($theme = $_COOKIE['theme']) {}
else {$theme = "Default";}
?>
<?php if($theme == "Default") { ?>
<$MTInclude module="DefaultMainIndex"$>
<?php } else if($theme == "Hogehoge") {?>
<$MTInclude module="HogehogeMainIndex"$>
<?php } ?>
のようにします。これによって
とすることでテンプレートを選べるようになります。 Default の場合は「DefaultMainIndex」を、Hogehoge の場合は 「HogehogeMainIndex」を読み込むことになります。用意してない場合は真っ白になると思います。
Category Archive、Date-Based Archive、Individual Entry Archive などに関しても同様のことを行います。この切り替えテンプレートの「MainIndex」の部分を「CategoryArchive」のように置き換えます。
ダイナミックパブリッシングの場合、もう少し工夫して、次のようにできます。
<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('function', 'MTInclude', 'mt:24', 9, false),array('function', 'MTBlogURL', 'mt:24', 10, false),)), $this);?>
<?php
$MTBlogURL = smarty_function_MTBlogURL(array(), $this);
$url = parse_url($MTBlogURL);
$path = $url['path'];
if($theme = $_GET['theme']) {setcookie('theme', $theme, 0, $path);}
else if($theme = $_COOKIE['theme']) {}
else {$theme = "Default";}
echo smarty_function_MTInclude(array('module' => ($theme)."MainIndex"), $this);
?>
動作的な違いは、if 文がなくなったことです。 こちらのほうが編集しなおさずにすむためテーマの追加が楽ですね。
4. 切り替えメニューを作ろう
簡単に切り替えられるようにするため、メニューを作りましょう。
<form action="" method="get">
<select name="theme" onchange="submit();" size="3">
<option value="Default">Default</option>
<option value="Hogehoge">Hogehoge</option>
</select>
</form>
を「Default Main Index」など Main Index 系テンプレートモジュールの適当なところ(sidebar など)に配置します。
余談ですが、これ自体もテンプレートモジュール化してそれぞの Main Index 中で
のように呼び出すのもまたありです。
5. あとがき
5.1 スタイルシート
スタイルシートも同様に切り替えることは理論上可能ですが、やめたほうがよさそうです。 ファイル名が同じなためか、IE が変化していない同じスタイルシートだと誤認してしまいます。 よって、単純に default.css, hogehoge.css のように別々のファイルにしてしまい、「DefaultMainIndex」で default.css を 「HogehogeMainIndex」では hogehoge.css を読み込む、のようにテンプレートを編集したほうがよいです。
5.2 php 拡張子の場合はファイルサイズが肥大化する
php 拡張子の場合、生成される php ファイルには MTInclude module で指定 したテンプレートがすべて展開されています。 それを php の if 文で無視させているだけです。 なので3つのテンプレートがあれば、通常の3倍の容量の php ファイルになるでしょう。 ユーザーに転送されるデータ量は if 文のおかげで通常と同じだけですが、 ハードディスクが圧迫されます。 php 拡張子時は、可能ではありますが、おすすめしません。
5.2 ダイナミックパブリッシング用テンプレート
ダイナミックパブリッシング用にできあがったものをおいておきます。 Stylesheet, Master Archive Index も一応作っておきました。
Trackback on "着せ替えMovable Type"
以下18件のトラックバックはこのページのエントリー"着せ替えMovable Type"を参照しています。
このエントリーのトラックバックURL:
» Ephedra lawyers southern california.
- August 21, 2008 09:10 PM
- from Ephedra lawyers southern california.
Ephedra lawyers california. Ephedra lawyers southern california. [続きを読む]
» Mp3 ringtones.
- September 1, 2008 06:34 PM
- from Create ringtones mp3.
Free mp3 ringtones. Download free mp3 ringtones. Ringtones mp3. [続きを読む]
» Altace and withdrawal.
- September 4, 2008 12:46 AM
- from Altace.
What is the generic name for altace. Altace. Altace medicine. [続きを読む]
» Propecia.
- October 13, 2008 06:38 AM
- from Propecia.
Pill propecia. Propecia merck propecia online uk. Propecia reverse impotence. [続きを読む]
» Tramadol.
- May 3, 2009 08:31 AM
- from Tramadol.
Buy tramadol online cod. Tramadol cod. Tramadol. [続きを読む]
» Hydrocodone.
- May 4, 2009 03:45 AM
- from Hydrocodone.
Hydrocodone. Hydrocodone guaifenesin syreth. [続きを読む]
» Oxycontin.
- May 4, 2009 07:48 AM
- from Purchasing oxycontin without a prescription.
Hartford oxycontin attorneys. Oxycontin. Craigslist oxycontin. Oxycontin pills. Lyrics to el-p oxycontin. Where to buy oxycontin. [続きを読む]
» Tramadol.
- June 21, 2009 11:37 PM
- from Tramadol.
Tramadol 180. Snorting tramadol. Tramadol. [続きを読む]
» Xanax during pregnancy.
- August 12, 2009 03:42 AM
- from Uhi foundation forums xanax cheap phentermine.
Buy xanax online. Xanax. Xanax online. [続きを読む]
» Propecia finasteride precautions amp side effects.
- August 14, 2009 02:42 AM
- from Propecia.
Nzlive com propecia rally new zealand. Propecia. Does propecia thin hair out at first. Propecia moins cher. Propecia side effects fre. What are the side effects of propecia. Buy propecia. About propecia online information uk. [続きを読む]
» Tramadol.
- August 15, 2009 03:55 AM
- from Tramadol.
Cheap tramadol. Tramadol with saturday delivery. Best price for tramadol. Tramadol withdraw. Tramadol. [続きを読む]
» Why is my cycle length 32 days on clomid.
- August 16, 2009 02:37 AM
- from Clomid for twins.
Clomid and determining gender. Can clomid cause miscarri. Buy clomid. Clomid. Clomid success. Clomid directions. [続きを読む]
» Buy levitra online.
- August 17, 2009 01:10 AM
- from How long does levitra last.
Buy sublingual levitra online. Generic levitra. Levitra attorneys. Levitra.com. Levitra. [続きを読む]
これを試してみたのですがうまくいきませんでした(ノД`) main indexで「Parse error: parse error, unexpected T_ELSE in */**/index.php」とでてしまうのですが・・・・
もうしわけない。else if の前に閉じかっこ忘れてました。php 拡張子の場合のやつですよね?ありがとうございました。
はい、php拡張子の場合です。それで、どのelse if を閉じれば良いのでしょうか?
もう直っています。コピペしなおしてください。
できました~~、ありがとうございます^-^