2016-05-05 8 views
0

基本的なランディングページhttp://shurity.com/をまとめてコードを整理しようとしていますが、静的コンテンツをユーザーの動的コンテンツに置き換えたかったのです。カスタムポストタイプにカスタムフィールドが表示されない

この要素は、購読をクリックするとポップアップするモーダルです。ループに含めるときにテキストが表示されません。次のコードは、私がモーダルに対して作成したカスタム投稿の種類と一致するテンプレートファイルです。投稿の種類には、モーダルのタイトル、本文、およびフッターのテキストの3つのカスタムフィールドがあります。 the_content()は実際のフォームを引っ張っています。

<?php 
$modal_header = get_field('modal_header'); 
$modal_body = get_field('modal_body'); 
$modal_footer = get_field('modal_footer'); 

?> 

<!-- MODAL 
================================================== --> 
<div class="modal fade" id="myModal"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 

     <?php 
      $args = array(
       'post_type' => 'modal', 
       'posts_per_page' => 1 
       ); 

      $loop = new WP_Query($args); ?> 


       <?php 
       if ($loop -> have_posts()) : 

        /* Start the Loop */ 
        while ($loop -> have_posts()) : $loop -> the_post(); 

         /* 
         * Include the Post-Format-specific template for the content. 
         * If you want to override this in a child theme, then include a file 
         * called content-___.php (where ___ is the Post Format name) and that will be used instead. 
         */ 
         //get_template_part('template-parts/content', get_post_format()); 
         ?> 

         <div class="modal-header"> 
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
          <h4 class="modal-title" id="myModalLabel"><i class="fa fa-envelope"></i> <?php echo $modal_header; ?></h4> 
         </div><!-- modal-header --> 

         <div class="modal-body"> 
          <p><?php echo $modal_body; ?></p> 

          <?php the_content(); ?> 
         </div><!-- modal-body --> 

         <hr> 

         <p><small><?php echo $modal_footer; ?></small></p> 

        <?php endwhile; 

       else : 

        get_template_part('template-parts/content', 'none'); 

       endif; ?> 

       <?php wp_reset_postdata(); ?> 

     </div><!-- modal-content --> 
    </div><!-- modal-dialog --> 
</div><!-- modal --> 

私はfooter.phpでこのテンプレート部分を呼び出しています。私はWordpressの新しいですので、間違いが明らかであれば私をよろこんでください。基本的にフォームが表示されますが、私の3つのカスタムフィールドは表示されません。これは、あなたが実際WP_Query前にフィールドを取得しようとしている

enter image description here

答えて

1

...それが今のように見えるものです。

ループ内でこのコードを配置:

while ($loop -> have_posts()) : $loop -> the_post(); 

    $modal_header = get_field('modal_header'); 
    $modal_body  = get_field('modal_body'); 
    $modal_footer = get_field('modal_footer'); 

    .... 
+0

はあなたに働く先生、ありがとうございました。 – CZorio

関連する問題