前提・実現したいこと
医療系のWPサイトを作っています。
料金表のカスタム投稿を設定し、それに対しカスタムフィールドを設定しています。
タームを複数設定してあり、料金表ページひとつのみでターム別にタイトルを表示、
その中に登録してある品目のタイトル・治療前写真・治療後写真・特徴・欠点・金額項目名・金額
追加で、登録が必要な場合にふたつめの金額項目名・金額・金額に対する注釈を用意したいと思い、
実装していっています。
現在、ここまでたどり着いたのですが、以下のエラーに行き詰まっているので
解決策を教えていただけると大変助かります。
デザイナー上がりのため構文に変なところ多々あるかと思いますが、
何卒よろしくお願い致します。
発生している問題・エラーメッセージ
・治療前・治療後の写真をそれぞれターム別、登録品目に紐付いた画像を表示させたい。
・カスタムフィールドに入力がある場合の<?php if(get_field('')): ?>がターム別記事一覧だと効かないようなので正しい書き方が知りたい。
該当のソースコード
PHP
1<?php 2 $taxonomy_name = 'price_cat'; 3 $taxonomys = get_terms($taxonomy_name); 4 if(!is_wp_error($taxonomys) && count($taxonomys)): 5 foreach($taxonomys as $taxonomy): 6 $tax_posts = get_posts(array( 7 'post_type' => get_post_type(), 8 'posts_per_page' => 5, 9 'tax_query' => array( 10 array( 11 'taxonomy' => 'price_cat', 12 'terms' => array($taxonomy->slug), 13 'field' =>'slug', 14 'include_children' => true, 15 'operator' => 'IN' 16 ), 17 'relation' =>'AND' 18 ) 19 )); 20 if($tax_posts): 21 ?> 22 <div class="category"> 23 <h2><?php echo esc_html($taxonomy->name); ?></span></h2> 24 <ul class="price-list"> 25 <?php foreach($tax_posts as $tax_post): ?> 26 <li> 27 <h3><?php the_title(); ?></h3> 28 <div class="treatment-photo"> 29 <div class="before-treatment"> 30 <?php 31 $image = get_field('before_treatment'); 32 if(!empty($image)){ 33 $url = $image['url']; 34 $alt = $image['alt']; 35 $title = $image['title']; 36 $size = 'thumbnail'; 37 $imgThumb = $image['sizes'][ $size ]; 38 $width = $image['sizes'][ $size . '-width' ]; 39 ?> 40 <figure class="img-wrap"> 41 <img src="<?php echo $imgThumb; ?>" width="<?php echo $width; ?>" alt="<?php echo $alt; ?>" /> 42 </figure> 43 <p>治療前</p> 44 <?php } ?> 45 </div> 46 <div class="after-treatment"> 47 <?php 48 $image = get_field('after_treatment'); 49 if(!empty($image)){ 50 $url = $image['url']; 51 $alt = $image['alt']; 52 $title = $image['title']; 53 $size = 'thumbnail'; 54 $imgThumb = $image['sizes'][ $size ]; 55 $width = $image['sizes'][ $size . '-width' ]; 56 ?> 57 <figure class="img-wrap"> 58 <img src="<?php echo $imgThumb; ?>" width="<?php echo $width; ?>" alt="<?php echo $alt; ?>" /> 59 </figure> 60 <p>治療後</p> 61 <?php } ?> 62 </div> 63 </div> 64 <div class="treatment-txt"> 65 <dl class="treatment-feature"> 66 <dt>特徴</dt> 67 <dd> 68 <?php echo $tax_post->{'treatment_feature'}; ?></dd> 69 </dl> 70 <dl class="disadvantages-feature"> 71 <dt>欠点</dt> 72 <dd> 73 <?php echo $tax_post->{'disadvantages_treatment'}; ?></dd> 74 </dl> 75 <p class="price"> 76 <?php echo $tax_post->{'treatment_fee_item'}; ?><span class="treatment-fee"><?php echo $tax_post->{'treatment_fee'}; ?>円</span> 77 </p> 78 <?php if(get_field('treatment_fee_item_2')): ?> 79 <p class="price"> 80 <?php echo $tax_post->{'treatment_fee_item_2'}; ?><span class="treatment-fee_2"><?php echo $tax_post->{'treatment_fee_2'}; ?>円</span> 81 </p> 82 <?php endif; ?> 83 <?php if(get_field('treatment_fee_supplement')): ?> 84 <p class="treatment-fee-supplement"> 85 <?php echo $tax_post->{'treatment_fee_supplement'}; ?> 86 </p> 87 <?php endif; ?> 88 </div> 89 </li> 90 <?php endforeach; ?> 91 </ul> 92 </div> 93 <?php 94 endif; endforeach; endif; 95 ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/24 08:40
退会済みユーザー
2018/03/24 08:43
2018/03/24 13:38