single.phpをカテゴリ毎に分岐したかったけど、できなくて…

WordPressの個別記事ページをカテゴリ毎に違うものにしたかったので、分岐を書きました!!

<?php
	if(in_category('information')){
		include(TEMPLATEPATH . '/single-information.php');
	}
	elseif(in_category('event')){
		include(TEMPLATEPATH . '/single-event.php');
	}
	elseif(in_category('blog')){
		include(TEMPLATEPATH . '/single-blog.php');
	}
	else{
		include(TEMPLATEPATH . '/single-defalut.php');
	}
?>

全部、single-defalut.phpが読み込まれてる…
分岐できてないなんで…

.
.
.

こちらのサイトに行き着きました。

WordPressでカテゴリー毎にsingle.phpのデザインを変更する方法

<?php
	$post = $wp_query->post;
?>

これがいるんだって。追加したらできたよ。
これなに?なんでいるの?

誰か教えて〜〜。

完成品

<?php
	$post = $wp_query->post;
	if(in_category('information')){
		include(TEMPLATEPATH . '/single-information.php');
	}
	elseif(in_category('event')){
		include(TEMPLATEPATH . '/single-event.php');
	}
	elseif(in_category('blog')){
		include(TEMPLATEPATH . '/single-blog.php');
	}
	else{
		include(TEMPLATEPATH . '/single-defalut.php');
	}
?>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA