ページごとにデザイン変更(Custom Post Template)
wordpressの記事も多くなってきてカテゴリも多くなると、カテゴリごとやページごとにデザインを変更したくなります。
プラグインを調べていたら「Custom Post Template」というページごとにデザインを変更できるプラグインがありました。
※説明の画面はwordpress2.71です。
ダウンロード
wordpress本家の「Plugin Direction」からダウンロードができます。
Custom Post Template とは
「Custom Post Template」についての説明があったので翻訳します。
Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post.
投稿編集画面から、投稿ごとに異なるテンプレートを選択できるドロップダウンを提供します。それらのテンプレートはページテンプレートと同様に定義され、指定された投稿では「single.php」と置き換えます。
オリジナルテンプレートの作成
Post templates, as far as this plugin is concerned, are configured similarly to page templates in that they have a particular style of PHP comment at the top of them. Each post template must contain the following, or similar, at the top:
このプラグインに限り、投稿テンプレートでは、テンプレートコードのトップに特定のスタイルのphpコメントを記述します。各投稿テンプレートのトップに次のコードを含めてください。
<?php
/*
Template Name Posts: Snarfer
*/
?>
例)
プラグインはインストールして有効にします。インストールの仕方は他のプラグインと同様です。
テンプレート「single.php」 をコピーし、 「single_hsp3.php」という名前で「single.php」と同じフォルダーに保存しました。
テーマ編集では、右サイドメニューに「single_hsp3.php」が追加されています。クリックすると編集することができます。
このテンプレート名は「single_hsp3」としたいので次のようにテンプレートのトップにコメントを記述しました。
<?php
/*
Template Name Posts: single_hsp3
*/
?>
投稿画面に「Post Template」が追加されています。ドロップダウンの選択にはデフォルトテンプレートと、上記で作成した「single_hsp3」があります。
このように投稿ごとにドロップダウンでテンプレートが選択できるようになりました。
2009 年 7 月 22 日 水曜日 【 カテゴリー: Wordpress2.7 , プラグイン 】




2010 年 5 月 10 日 7:12 PM
[...] Post Template) http://memories.zal.jp/WP/20090722_1591.html Posted in [WP] ワードプレス | Tags: [...]