度々お世話になります。
PHP初心者です...。
Advanced Custom Fieldsを使用し、カスタム投稿を作成しています。
ラジオボタンの項目で、商品のバリエーションあり、なしの選択肢を作成いたしました。
- フィールドラベル
商品バリエーション - フィールド名
size_color - 内容
enable : ある(種類あり)
disable : ない(種類なし)
というように設定し、
あるの場合は、出力が<form>にて選択するように、
ないの場合は<a href>にて直接リンク先に飛ばすようにしたいです。
なお、分岐させた中にも販売状況も反映させたいです。
Advanced Custom Fields側での設定は完了しており、(上記選択肢により、その後のカスタム投稿画面も条件で表示非表示設定がしてある)
問題は出力側です。
PHP
1get_header(); ?> 2 3 <div id="primary" class="content-area"> 4 <div id="content" class="site-content" role="main"> 5 <?php while ( have_posts() ) : the_post(); ?> 6 7 <?php 8 $txt = get_field('product_name'); 9 if($txt){ ?> <h1 class="entry-title"> <?php echo $txt; ?> </h1> 10 <? } 11 ?> 12 13 <div class="entry-content"> 14 <?php 15 $txt = get_field('product_image'); 16 if($txt){ ?> 17 <?php 18 if ( function_exists( 'soliloquy' ) ) { soliloquy($txt); } 19 } ?> 20 21 <?php 22 $txt = get_field('product_text'); 23 if($txt){ ?> 24 <div style="word-wrap:break-word";> 25 <h4><? echo $txt; ?></h4></div> 26 <? } 27 ?> 28 29 <?php 30 $txt = get_field('product_spec'); 31 if($txt){ ?> 32 <p><? echo $txt; ?></p> 33 <? } 34 ?> 35 36 <?php 37 $txt = get_field('price'); 38 if($txt){ ?> 39 <span style="font-size:40px; color:#FF0000;"> <? echo $txt; ?></span> 40 <? } 41 ?> 42 43 <span style="color: #ee0000;"> 44 (税込) 45 </span> 46 47 <?php 48 $radio = get_field('size_color'); 49 if(get_field(' size_color ') == "enable"){?> 50 <form> 51 <div class="sel" style="text-align: center; margin-top:10px;"> 52 <select name="select2"> 53 <?php 54 $txt = get_field('size_color_input'); 55 if($txt){ echo $txt; }?> 56 <? echo $txt; ?> 57 </select> 58 <?php 59 $select = get_field('sell'); 60 if($select){?> 61 <input class="<? echo $select; ?>" type="button" value="" onclick="top.location.href=select2.value"> 62 } 63 } 64 65 <?php 66 if(get_field(' size_color ') == "disable"){?> 67 <?php 68 $txt = get_field('variation_off'); 69 if($txt){ echo $txt; } 70 $select = get_field('sell'); 71 if($select){ echo $select; }?> 72 <a href="https://hoge.com/p_id=<? echo $txt; ?>" class="<? echo $select; ?>"> 73 <?php endwhile; ?> 74 75 76 </div><!-- #content --> 77 </div><!-- #primary --> 78 79 <?php if(get_theme_mod('portfolio_show_post_navigation', '1') == '1') : ?> 80 <?php 81 previous_post_link( 82 '<div id="prev-post">%link</div>', 83 '<i class="fa fa-arrow-left"></i>', 84 (get_theme_mod('portfolio_show_post_navigation_same_taxonomy', '0') == '0' ? FALSE : TRUE) 85 ); 86 ?> 87 <?php 88 next_post_link( 89 '<div id="next-post">%link</div>', 90 '<i class="fa fa-arrow-right"></i>', 91 (get_theme_mod('portfolio_show_post_navigation_same_taxonomy', '0') == '0' ? FALSE : TRUE) 92 ); 93 ?> 94 <?php endif; ?> 95 96 <?php get_template_part( 'content', 'footer' ); ?> 97 <?php comments_template(); ?> 98 99<?php get_footer(); ?>
$radioの前までですとしっかりと表示されます。しかし、
こちらですと、endwhileの部分でエラーが出てしまい、動作確認もできず...
おそらく$radio以降、書き方が間違えているのではないかと思っています。
お恥ずかしい話なのですが、どこが間違えているか、ご教示いただければと思います。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。