5⃣ page-service.php部分のCustom Field Template設定‐オリジナルをつくる編‐
2016/04/06
❿ page-service.php部分のCustom Field Template設定‐オリジナルをつくる編‐
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[syohin] type = text size = 35 label =商品名を入力してください。 [kakaku] type = text size = 35 label =価格を数字で入力してください。例)2,000 [size] type = text size = 35 label =サイズを数字で入力してください。例)60 [toksyo] type = text size = 35 label =特徴を入力してください。 |
このように投稿記事を記述できるようになります。
⓫ page-service.php部分にテンプレートに出力するコードを記述する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<?php get_header(); ?> <div id="contents"> <div id="main"> このページはサービスの更新ページです。 <section> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <?php endwhile; else: ?> <p>投稿は記事はありません。</p> <?php endif;?> <?php $loop = new WP_Query(array("post_type" =>"service","posts_per_page" =>10)); while($loop->have_posts()): $loop->the_post(); ?> <?php $shohin = post_custom('shohin'); ?> <?php $kakaku = post_custom('kakaku'); ?> <?php $size = post_custom('size'); ?> <?php $tokucho = post_custom('tokucho'); ?> <section class="list"> <a href="<?php the_permalink(); ?>"> <h4><?php the_title(); ?></h4> <figure><?php the_post_thumbnail(array(200,133)); ?></figure> <table> <tr> <th>商品名</th> <td><?php echo $shohin; ?></td> <th>価格</th> <td><?php echo $kakaku; ?>円</td> </tr> <tr> <th>サイズ</th> <td><?php echo $size; ?>kg</td> <th>特徴</th> <td><?php echo $tokucho; ?></td> </tr> </table> <p><?php the_content(); ?></p> </a> </section> <?php endwhile; ?> </section> </div> <!--/main--> <?php get_sidebar(); ?> <?php get_footer(); ?> |
このように表示されます。
⓬ single.php部分にテンプレートに出力するコードを記述する
pege.phpを複製してsingle.phpを作ります。製品情報とアイキャッチを出力する記述をします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
<?php get_header(); ?> <div id="contents"> <div id="main"> <section> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <?php $shohin = post_custom('shohin'); ?> <?php $kakaku = post_custom('kakaku'); ?> <?php $size = post_custom('size'); ?> <?php $tokucho = post_custom('tokucho'); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <figure class="mb15 c"> <!---<?php the_post_thumbnail(); ?></figure>-サイズ指定なし--> <!--<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>" width="800" height="100" > </figure>画像を指定---> <?php the_post_thumbnail(array(800,200)); ?> <table class="ta1 mb15"> <caption>テーブルのキャプションを付ける場合はこれを使います</caption> <tr> <th>商品名</th> <td><?php echo $shohin; ?></td> </tr> <tr> <th>価格</th> <td><?php echo $kakaku; ?>円</td> </tr> <tr> <th>サイズ</th> <td><?php echo $size; ?>kg</td> </tr> <tr> <th>特徴</th> <td><?php echo $tokucho; ?></td> </tr> </table> </article> <p><a href="javascript:history.back()"><< 前のページに戻る</a></p> <?php endwhile; else: ?> <p>投稿の記事はありません。</p> <?php endif;?> </dl> </section> <!-- ▼前か次のページが存在する場合のみ表示する▼ --> <?php if( get_previous_post() || get_next_post() ){ ?> <!-- ページャー --> <div style="width:100%"> <?php if( get_previous_post() ): ?> <div style="float:left"> <?php previous_post_link('%link', '≪ %title'); ?> </div> <?php endif; if( get_next_post() ): ?> <div style="float:right"> <?php next_post_link('%link', '%title ≫'); ?> </div> <?php endif; ?> </div> <!-- /ページャー --> <?php } ?> <!-- ▲前か次のページが存在する場合のみ表示する▲ --> </div> <!--/main--> <?php get_sidebar(); ?> <?php get_footer(); ?> |
次のページをご覧ください。
PAGE 1 PAGE 2