smart custom fieldsでのチェックボックスの値の出力について
-
smart custom fieldsを使い、繰り返しフィールドに設定したグループ内にチェックボックスの項目を作っています。
チェックボックスで何も選択していない場合は、タグごと出力しないようにしたいのですが、現在以下の書き方で、空の<span></span>が生成されてしまいます。<?php $scf_list_flg = get_post_meta( $id, 'scf_ttl', true); if($scf_list_flg) { $output_scf_list = '<ul class="scf-list">'; $scf_list_grp = SCF::get( 'scf_list_grp' ); foreach($scf_list_grp as $scf_list) { $ttl = $scf_list['scf_ttl']; $scf_check_flg = SCF::get( 'scf_check' ); if($scf_check_flg) { $check = "<span>".implode("</span><span>", $scf_list['scf_check'])."</span>"; } $output_scf_list .= '<li><p>'.$ttl.'</p><p>'.$check.'</p></li>'; } $output_scf_list .= '</ul><!-- /.scf-list -->'; echo $output_scf_list; } ?>
出力は以下の様な状態で、ラストのliタグ内にspanの空タグが出力されています。
<ul class="scf-list"><li><p>タイトル</p><p><span>WEB</span></p></li><li><p>タイトル2</p><p><span>PHOTO</span></p></li><li><p>タイトル3</p><p><span>MOVIE</span><span>PHOTO</span></p></li><li><p>タイトル4</p><p><span></span></p></li></ul><!-- /.scf-list -->
尚、チェックボックスの名前は scf_check と設定しており、選択肢には値のみを入力しています。
勉強不足で恐縮ですが、どうぞよろしくお願いいたします。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「smart custom fieldsでのチェックボックスの値の出力について」には新たに返信することはできません。