Wordpessアーカイブページで特定のカスタムフィールドの値を持つ投稿の見出し付き一覧を作成したいです。
ここに質問の内容を詳しく書いてください。
現在、アーカイブページ(archive-hogehoge.php)にて商品一覧ページを作成しています。
商品にはそれぞれシリーズがA・B・C・Dとあり、シリーズごとに見出しをつけてループで一覧表示させたいと思っております。
各シリーズごとに見出しは1つでイメージは下記になります。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
A.series
商品A 商品A 商品A
B.series
商品B 商品B 商品B
.
.
.
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
発生している問題・エラーメッセージ
現状下記のようになってしまっているので
理想的な形になりません。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
A.series
商品A
A.series
商品A
A.series
商品A
B.series
商品B
B.series
商品B
B.series
商品B
.
.
.
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
問題のソースコード
PHP
1<?php 2 $series = array('A','B','C','D',); 3 $args = array( 4 'meta_key' => "series", 5 'sort_order' => 'ASC', 6 'sort_column' => 'post_date', 7 'post_type' => 'hogehoge', 8 ); 9 foreach ($series as $serieskey => $seriesval) : 10 $args['meta_value'] = $seriesval; 11 $myposts = get_posts($args); 12 foreach($myposts as $post): 13 setup_postdata($post); 14?> 15 <h3 id="<?php echo $seriesval; ?>series"><?php echo $seriesval ?>.series</h3> 16 <div class="collection_block"> 17 <?php if ( get_post_meta( get_the_ID(), 'main_img', true ) ) : ?> 18 <?php 19 $src02 = wp_get_attachment_image_src($cfs->get('main_img'), 'size_collection'); 20 ?> 21 <input type="hidden" value="<?php echo $src02[0];?>" class="main_img"> 22 <?php endif;?> 23 <?php if ( get_post_meta( get_the_ID(), 'side_img', true ) ) : ?> 24 <?php 25 $src = wp_get_attachment_image_src($cfs->get('side_img'), 'size_collection'); 26 ?> 27 <input type="hidden" value="<?php echo $src[0];?>" class="side_img"> 28 <?php endif;?> 29 <a href="<?php the_permalink();?>"> 30 <?php if ( get_post_meta( get_the_ID(), 'main_img', true ) ) : ?> 31 <?php 32 $attachment_id = $cfs->get('main_img'); 33 ?> 34 <?php 35 $attachment_image = wp_get_attachment_image( $attachment_id ); 36 echo wp_get_attachment_image(post_custom('main_img'),'size_collection'); 37 ?> 38 <?php else :?> 39 <img src=<img src="http://placehold.it/700x400?text=noimage">" alt="<?php the_title();?>"> 40 <?php endif;?> 41 <p class="entry_item_name"><?php the_title();?></p> 42 </a> 43 </div> 44 45 <?php endforeach; wp_reset_postdata(); endforeach; ?>
よろしくお願いいたします。
補足情報(FW/ツールのバージョンなど)
カスタムフィールドの値は
Custom Field Suite
というプラグインで埋め込みしています。
$mypostsの中身は該当シリーズ(ループ実行中)の記事データが配列形式で格納されています。
回答1件
あなたの回答
tips
プレビュー