singleページで特定のカテゴリを除外する
-
singleページをスラッグ「news」と「blog」をsingle-news.phpとsingle-blog.phpに分けていて、
single-blog.phpでの親カテゴリ「blog」の子カテゴリ一覧を表示しています。「blog」の子カテゴリのみを表示したいのに、「news」の記事も表示されてしまい、困っています。
—–
<dl> <?php global $post; $cats = get_the_category(); $cat_posts = get_posts(array( 'post_type' => 'post', // 投稿タイプ 'posts_per_page' => 5, // 表示件数 'orderby' => 'date', // 表示順の基準 'order' => 'DESC', // 昇順・降順 )); $count = count($cat_posts); if ($count >= 1): foreach ($cat_posts as $post): setup_postdata($post);?> <dt><?php the_time('Y.m.d');?><span><?php $cats = get_the_category(); foreach($cats as $cat): if($cat->parent) echo $cat->cat_name; endforeach; ?></span></dt><dd id="post-<?php the_ID();?>"><a href="<?php the_permalink()?>"><?php the_title();?></a></dd> <?php endforeach; wp_reset_postdata();else: ?> <p>記事がありません。</p> <?php endif;?> </dl>
—–
色々調べましたが上手くいかず、どのように修正すれば「news」の記事が出ないように出来るか教えていだだきたいです。
ヘルプの必要なページ: [リンクを見るにはログイン]
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「singleページで特定のカテゴリを除外する」には新たに返信することはできません。