実現したいこと
phpを用いてwordpressのサイトを作成しています。
サイトのトップで、3種類のタイプの最新投稿記事のサムネイルを6件表示させていますが、
その内1種類のみ各カテゴリ(term)の最新記事を1件だけ表示する仕様にしたいです。
投稿タイプA、B、Cの最新投稿記事を計6件表示させたいが、その内CはtermがD、E、Fとある。
Cは各term1件のみの表示にした上で、全部で6件の表示は崩さないままにしたい。
初心者なので質問の仕方に至らない部分がありますが、よろしくお願いします。
該当のソースコード
PHP & HTML
※長いので一部抜粋しています。
<h2 class="section-c__title"> <span class='en'>C</span> </h2> <?php endif; ?> <?php endwhile; ?> <?php endif; ?><?php $count = 0; while ($post_query -> have_posts()): $post_query -> the_post(); $post_category = array_shift(get_the_category( get_the_ID() )); $count++; ?> <?php elseif(get_post_type() == 'C'): ?> <?php if(empty($post_category) && get_the_terms( get_the_ID(), 'c-title' )) $post_category = array_shift(get_the_terms( get_the_ID(), 'c-title' )); $post_cover = types_render_termmeta("category-cover-image", array( "url"=>"true", "term_id" => $post_category->term_id, "alt" => "", "resize" => "proportional", "size" => "x-large" ) ); $post_title = '<a href="'.get_category_link( $category->cat_ID ).'">'.$post_category->name.'</a>'; $column_number = get_post_meta(get_the_ID(),'wpcf-column_number',true); ?>
試したこと
Cのif文の中でtax_Queryを使用し'posts_per_page'=> 1の指定。
Query_postでposts_per_pageの指定。
あなたの回答
tips
プレビュー