wordpressにて店舗が自分のショップ情報を投稿できるようにするページを作成しようとしてるのですが、カスタム投稿がまだまだわからず記事一覧も個別ページもうまく表示されません。
参考サイト1
こちらを参考にして進めました。
functions.phpにはこういうふうに追加しました。メニューの左側にショップ登録は出てきてます。
php
1 2//カスタム投稿タイプの追加 INFORMATION 3add_action('init', 'info_init'); 4function info_init() 5{ 6 $labels = array( 7 'name' => _x('ショップ登録', 'post type general name'), 8 'singular_name' => _x('shop登録', 'post type singular name'), 9 'add_new' => _x('新しくショップを登録', 'item'), 10 'add_new_item' => __('新規ショップを登録する'), 11 'edit_item' => __('ショップを編集'), 12 'new_item' => __('新しいショップ'), 13 'view_item' => __('ショップを見る'), 14 'search_items' => __('ショップを探す'), 15 'not_found' => __('ショップはありません'), 16 'not_found_in_trash' => __('ゴミ箱にショップはありません'), 17 'parent_item_colon' => '' 18 ); 19 $args = array( 20 'labels' => $labels, 21 'public' => true, 22 'publicly_queryable' => true, 23 'show_ui' => true, 24 'show_admin_column' => true, 25 'query_var' => true, 26 'rewrite' => true, 27 'capability_type' => 'post', 28 'hierarchical' => true, 29 'menu_position' => 5, 30 'supports' => array('title'), 31 'has_archive' => true, 32 ); 33 register_post_type('informationshop',$args); 34} 35 36 37?> 38
Advanced Custom Fieldsにはこうしてます。
archive-informationshop.phpを作成して、おそらくその部分をまるまるコピペしてるからget_fieldの部分で自分の設定したのと合ってないから取得できず表示されないのかなと思ってますが、phpはあまりわかってません。こうしてます
php
1<?php if ( have_posts() ) { ?> 2 <?php while ( have_posts()) { 3 the_post(); 4 $img = get_field('img'); 5 $imgurl = wp_get_attachment_image_src($img, 'full'); 6 $day = get_field('day'); 7 $title = get_field('title'); 8 $contents = get_field('contents'); 9 ?> 10 11 <article class="info_box cf"> 12 <div class="img"> 13 <img src="<?php echo $imgurl[0]; ?>" alt="インフォメーション<?php echo get_the_title( $ID ); ?>" width="202" height="152"> 14 </div><!-- //.img--> 15 <dl> 16 <dt><time pubdate="pubdate" datetime="<?php echo $day ; ?>"><?php echo $day ; ?></time> <?php echo $title ; ?></dt> 17 <dd><?php echo $contents ; ?></dd> 18 </dl> 19 </article><!-- //.info_box--> 20 <?php } // end of the loop.?> 21 22<?php } ?>
参考サイト2
こちらのサイトも参考にしてsingle-informationshop.phpも作成したのですが、作成しただけ中のコードがうまくわからず、
記事を書いて見てみた時に、記事の詳細ページはタイトル以外何も表示されず、記事一覧ページは作成した記事自体表示されません。
どうしたら良いか教えていただけないでしょうか?よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー