Custom Field Template の埋め込み
投稿にこれを埋め込む
ドットインストールで作成したテンプレで実験
投稿内容は
single.php にあるのでこれを編集する
参考サイトは
WordPressとプラグインを使ってお店紹介サイトを作る方法
だけど
最初の判定が
<?php if ( get_post_meta($post->ID,'Zip',TRUE) ):
で行っている
これは郵便番号がある場合だけど
私の場合、ほしいものだけに絞って
[Address] type = textarea cols = 80 rows = 3 label = 住所 [Time] type = text size = 35 label = 営業時間 [Holiday] type = text size = 35 label = 定休日 [Impression] type = textarea cols = 80 rows = 3 label = ひとことメモ [Map lat] type = text size = 35 label = 緯度 [Map lng] type = text size = 35 label = 経度
としているので、Zip がない
なので、判定を変更する
ちなみに、カスタムフィールドで入力した住所とかは
投稿画面にそのままだと表示されない
[<?php the_category(','); ?>]
で
>[<?php the_category(); ?>]
となっていると改行されてレイアウトが崩れるので注意
あと、SNSのボタンを
WP Social Bookmarking Light
で設置した場合
<?php the_content(); ?>
のところに表示される
まずはどのあたりに表示されるかを調べたかったので
<?php echo post_custom("Address")?>
を the_content() の前後に配置
これで住所がでたので
次に
判定などを追加していく
<?php if ( get_post_meta($post->ID,'Address',TRUE) ): ?> <h3><?php the_title(); ?>の情報</h3> <div class="infobox"> <table> <tr><td class="name">住所</td><td><?php echo post_custom("Address")?></td></tr> <tr><td class="name">営業時間</td><td><?php echo post_custom("Time")?></td></tr> <tr><td class="name">定休日</td><td><?php echo post_custom("Holiday")?></td></tr> </table> </div> <?php endif;?>
次に css の設定
.Infobox table{ margin: 0 0 20px 0; width: 575px; border-collapse: collapse; font-size:14px; } .infobox table td{ width:455px; padding:5px; word-break:break-all; line-height:1.3; border:1px solid #df9128; } .infobox table td.name{ width:120px; vertical-align:top; background-color: #ffe1b9; font-size:12px; } .infobox table td img{ margin: 0 5px 0 0; border:1px solid #343434; }
をファイル末尾に追加
これで店舗情報は表示できた
地図は、また後で考える
cssとテーブルタグで綺麗に仕上げている