カテゴリー別にサイドメニューを変更したい
-
カテゴリー別にサイドメニューに表示される内容を変えたいと思い、下記のようにしました。
これで一応思い通りに表示されるのですが、同じ内容が何度もでてくるので、もっと簡単にしたいのですが、思いつきません。もっと、コードを簡単にする方法を教えてください。
——————————————————————————-<?php if(!(is_home() || is_404() || is_search() || in_category(3))): ?> <!-- カテゴリー「時事」に属するタイトルの表示 --> <?php if(in_category(current)): ?> <nav id="cate-current"> <h2>カテゴリー|時事「異論反論オブジェクション」</h2> <ul> <?php $myposts = get_posts('category_name=current&numberposts=20'); foreach($myposts as $post) : // $post を使う setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); ?> </nav> <?php endif; ?> <!-- /cate-current --> <!-- カテゴリー「gmail関連」に属するタイトルの表示 --> <?php if(in_category(11)): ?> <nav id="cate-gmail"> <h2>カテゴリー|Gmail関連</h2> <ul> <?php $myposts = get_posts('category_name=gmail&numberposts=20'); foreach($myposts as $post) : // $post を使う setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); ?> </nav> <?php endif; ?> <!-- /cate-gmail --> <!-- カテゴリー「chrome関連」に属するタイトルの表示 --> <?php if(in_category(12)): ?> <nav id="cate-chrome"> <h2>カテゴリー|Chrome関連</h2> <ul> <?php $myposts = get_posts('category_name=chrome&numberposts=20'); foreach($myposts as $post) : // $post を使う setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); ?> </nav> <?php endif; ?> <!-- /cate-chrome --> <!-- カテゴリー「wordpress」に属するタイトルの表示 --> <?php if(in_category(wp)): ?> <nav id="cate-wp"> <h2>カテゴリー|wordpress</h2> <ul> <?php $myposts = get_posts('category_name=wp&numberposts=20'); foreach($myposts as $post) : // $post を使う setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); ?> </nav> <?php endif; ?> <!-- /cate-wordpress --> <?php endif; ?>
——————————————————————————-
ちなみに、同様のブロックが4つありますが、実際は10近くあります。もう一つ質問です。
<?php if(!(is_home() || is_404() || is_search() || in_category(3))): ?>
と指定すると、in_category(3)の子要素にも影響がでるようです。
親要素には表示させず、子要素に表示させるにはどうすればよいのでしょうか?よろしくお願いいたします。
15件の返信を表示中 - 1 - 15件目 (全15件中)
15件の返信を表示中 - 1 - 15件目 (全15件中)
- トピック「カテゴリー別にサイドメニューを変更したい」には新たに返信することはできません。