elegantthemeを使うと、
カテゴリー表示のページにいくと
子カテゴリーに含まれているものまで表示される。
それを、表題の通り
親カテゴリに子カテゴリの投稿を表示させない為の方法。
ブログじゃ無くてCMS的に使う場合に、良くありがちな設定だと思う。
the_posts(); の前にコードを入れるだけ。
elegantthemeの場合、
archive.php とかが存在しないので、
カテゴリーを表示する場合に使うファイルを見ると
include templeteとかで最終的に
entry.phpを読み込む設定になっている
だから、entry.phpをいじれば良いんだけど
the_posts();はどこにあるかっていうと
見たらすぐ分かる。
一番上・・・
だから、
entry.phpを開いたら、
何も考えずに、文字通り先頭に
以下のコードを入れればOK
[code language=”php”]$current_cat = get_query_var(‘cat’); if ($children = get_categories(‘child_of=’.$current_cat)) { $exclude = array(); foreach ($children as $child) $exclude[] = $child->term_id; query_posts(array(‘cat’=>$current_cat, ‘category__not_in’ => $exclude)); }[/code]
ちなみに、eleganttheme以外でも、場所は知らないけど、全部通用します。
0コメント