wordpressの質問です。カスタム投稿ページの話です。functions.phpにメタボックスを追記し、表示させることまではできました。緯度経度urのデータを投稿ページに持ってくる、表示させるようにすることってできるのでしょうか。
[single-location.php]
php
1<?php 2/* 3Template Name Posts: location 4*/ 5?> 6 7<?php 8 9get_header(); ?> 10 11<div class="wrap"> 12 <div id="primary" class="content-area"> 13 <main id="main" class="site-main" role="main"> 14 15 <?php 16 /* Start the Loop */ 17 while ( have_posts() ) : the_post(); 18 19 get_template_part( 'template-parts/post/content', get_post_format() ); 20 21 // If comments are open or we have at least one comment, load up the comment template. 22 if ( comments_open() || get_comments_number() ) : 23 comments_template(); 24 endif; 25 26 the_post_navigation( array( 27 'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>', 28 'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>', 29 ) ); 30 31 endwhile; // End of the loop. 32 ?> 33 34 </main><!-- #main --> 35 </div><!-- #primary --> 36 <?php get_sidebar(); ?> 37</div><!-- .wrap --> 38 39<!--投稿 --> 40<?php 41 $args = array( 42 'post_type' => 'location', 43 'tax_query' => array( 44 array( 45 'taxonomy' => 'location_category', 46 'field' => 'slug', 47 'terms' => 'boardgames' 48 ) 49 ) 50 ); 51 $location = new WP_Query( $args ); 52 if( $location->have_posts() ) { 53 while( $location>have_posts() ) { 54 $location->the_post(); 55 ?> 56 <h1><?php the_title() ?></h1> 57 <div class='content'> 58 <?php the_content() ?> 59 </div> 60 <?php 61 } 62 } 63 else { 64 echo 'Oh ohm no locations!'; 65 } 66?> 67 68<!--メタデータ取得 --> 69<?php 70 // If we are in a loop we can get the post ID easily 71 $lot = get_post_meta( get_the_ID(), 'lon', true ); 72 echo $lot; 73?> 74<?php get_footer(); 75 76
single.phpをコピーして新しい優先して読み込まれるはずの、テンプレートsingle-location.php(locationはカスタム投稿タイプ名)を作ったのですが、
緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。コードの書き方が悪いのでしょうか。それともコードをかくファイルがそもそも違うのでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/29 05:27
2017/04/30 02:41
2017/04/30 04:16
2017/04/30 06:39 編集
2017/04/30 06:43