Wordpressで、投稿記事の一覧を取得しようとしています。
しかし、問題が起きています。
▼問題
記事には1つのカテゴリしか設定していないのに、
一覧ページでは作成しているすべてのカテゴリで表示されてしまいます。
しかもカテゴリごとに記事が1件ずつ投稿されていて、
重複して投稿されているように見えています。
URL:https://www.fcl-hid.com/blog/information-news
記事は「お知らせ」または「レビュー」で設定しています。(2つを複数設定している記事は無し)
例えば新たに「イベント」で1件投稿したら、「イベント」で全記事が追加で表示されます。
コードに問題あるのでしょうか。
ご教授いただけますと幸いです。よろしくお願いいたします。
以下コード
<ul class="display-posts-listing"> <?php $args = array( 'numberposts' => 20, //表示(取得)する記事の数 'post_type' => 'information', //投稿タイプの指定 'taxonomy' => 'informationcat', 'show_count' => 0, 'hide_empty' => 1 ); $posts = get_posts( $args ); $categories=get_categories($args); foreach($categories as $category) { $catid = $category -> term_id; $catslug = $category -> slug; if( $posts ) : foreach( $posts as $post ) : setup_postdata( $post ); ?> <li class="listing-item"> <a href="<?php the_permalink(); ?>"> <div class="left"> <div class="img-wrapper"> <div class="img-box"> <?php if ( has_post_thumbnail()) { ?> <div class="image" style="background-image: url(<?php the_post_thumbnail_url( 'full' ); ?>);"></div> <?php } else { ?> <div class="image" style="background-image: url(<?php echo get_theme_file_uri( 'images/front/no_image.png' ); ?>);"></div> <?php } ?> </div> </div> </div> <div class="right"> <div class="content-inner"> <div class="cat-box"> <div class="category" id="<?php echo strtoupper($catslug);?>"><?php echo $category->name; ?></div> <div class="date"><?php the_time('Y/m/d'); ?></div> </div> <div class="title"><?php the_title(); ?></div> <div class="contents pc"><?php get_excerpt(60);?></div> <div class="contents sp"><?php get_excerpt(40);?></div> </div> <div class="posts-btn"><img src="https://fcl-support.com/wp-content/themes/fcl/img/common/info_btn.jpg" alt="詳細はこちら" width="270"></div> </div> </a> </li> <?php endforeach; ?> <?php else : //記事が無い場合 ?> <li> <p>記事はまだありません。</p> </li> <?php endif; wp_reset_postdata(); //クエリのリセット ?> <?php }?> </ul>
回答1件
あなたの回答
tips
プレビュー