▽1
●
rouge_2008 ●100ポイント ベストアンサー |
記事のサンプルコードでは、次の部分で登録した情報のボックス全体の表示を決めていました。(※郵便番号が保存されていると表示します。)
<?php if ( get_post_meta($post->ID,'Zip',TRUE) ): ?>
ただし、郵便番号が保存されていないと表示されませんので、次のようにして郵便番号と住所(セット)、電話番号、営業時間、休業日、座席数、経度および緯度(セット)、感想の何れかが保存されていた場合に表示されるようにしてはいかがでしょうか?
<?php if( ( post_custom("Zip") && post_custom("Address") ) || post_custom("Tel") || post_custom("Time") || post_custom("Holiday") || post_custom("Seat") || ( post_custom("Map_lat") && post_custom("Map_lng") ) || post_custom("Impression") ) : ?>
同じようにして、各項目ごとの行を条件分岐で表示すると良さそうです。
<table> <?php if( post_custom("Zip") && post_custom("Address") ) : ?> <tr><td class="name">住所</td><td>〒<?php echo post_custom("Zip")?><br /><?php echo post_custom("Address")?></td></tr> <?php endif; ?> <?php if( post_custom("Tel") ) : ?> <tr><td class="name">電話番号</td><td><?php echo post_custom("Tel")?></td></tr> <?php endif; ?> <?php if( post_custom("Time") ) : ?> <tr><td class="name">営業時間</td><td><?php echo post_custom("Time")?></td></tr> <?php endif; ?> <?php if( post_custom("Holiday") ) : ?> <tr><td class="name">定休日</td><td><?php echo post_custom("Holiday")?></td></tr> <?php endif; ?> <?php if( post_custom("Seat") ) : ?> <tr><td class="name">席数</td><td><?php echo post_custom("Seat")?></td></tr> <?php endif; ?> <?php if( post_custom("Map_lat") && post_custom("Map_lng") ) : ?> ...(略) </tr> <?php endif; ?> <tr> ...(略) </tr> <?php if( post_custom("Outward") || post_custom("Curry Photo1") || post_custom("Curry Photo2") ) : ?> <tr> ...(略) </tr> <?php endif; ?> </table> <?php endif; ?>
※上記の例では、郵便番号と住所、Map_latとMap_lngは、それぞれ両方保存されていた場合に表示するようにしています。
※カスタムフィールドの名前はサンプルコードと同じになっていますので、実際の使用状況に合わせて適宜変更してください。