2016-08-31 1 views
0

ここで私のダブルループクエリで何かがうまく動作していないのですが、正確にはわかりません。基本的には、自分のブログページにACFを使用してRepeaterフィールドを提供しています。ここで、自分のタブに表示するカテゴリ/タクソノミーを選択できます。だから、タブの名前をうまく引っ張っていますが、そこにコンテンツを生成することはできません。 "reset_rows();"を追加する必要があることが示唆されましたが、これはページを永久に読み込むように見えますが、実際のコンテンツはまだ作成されていません。ACFを使用してタクソノミのブートストラップタブを生成する

ここは私のループです。どのような助けをしても大歓迎です。

<!-- Nav Tabs --> 
<ul class="nav nav-pills"> 
    <?php if (have_rows('home_categories')) { 
     $i = 0; 
     while (have_rows('home_categories')) { 
      the_row(); 
      $term = get_sub_field('categories'); ?> 
    <li class="<?php if ($i == 0) { echo ' active'; }?>"> 
     <a href="#<?php echo $term->name; ?>" data-toggle="tab"><?php echo $term->name; ?></a> 
    </li> 
     <?php $i++; 
     } 
    } ?> 
</ul> 

<!-- Tab Content --> 
<div class="tab-content clearfix"> 
    <?php if (have_rows('home_categories')) { 
     $i = 0; 
     while (have_rows('home_categories')) { 
      the_row(); 

      $args = array(
       'post_type' => 'post', 
       'tax_query' => array(
        array(
         'taxonomy' => $term->taxonomy, 
         'terms' => array($term_id) 
        ) 
       ), 
       'posts_per_page' => 5, 
       'orderby' => 'date', 
       'order' => 'ASC', 
      ); 
      $post = new WP_Query($args); 
      while($post->have_posts()) : $post->the_post(); 

      $term = get_sub_field('categories'); ?> 

       <div class="tab-pane fade<?php if ($i == 0) { echo ' in active'; }?>" id="<?php echo $term->name; ?>"> 
        <?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive img-thumbnail')); ?> 
        <a href="<?php echo get_permalink(); ?>"><h3><?php the_title(); ?></h3></a> 
        <?php the_excerpt(); ?> 
       </div> 
      <?php endwhile; 
     } 
     $i++; 
    } 
     wp_reset_postdata(); ?> 
</div> 

答えて

0

私はこれに取り組んで、他のプログラマーの友人に助けを求めるように依頼しました。私たちは、だけではなく、しばらくのforeachのとタブのコンテンツエリアを書き直し、今ではかなりうまく動作するようです:

<!-- Nav Tabs --> 
<ul class="nav nav-pills"> 
    <?php if (have_rows('home_categories')) { 
     $i = 0; 
     while (have_rows('home_categories')) { 
      the_row(); 
      $term = get_sub_field('categories'); ?> 
    <li class="<?php if ($i == 0) { echo ' active'; }?>"> 
     <a href="#tab-pane-<?php echo $i; ?>" data-toggle="tab"><?php echo $term->name; ?></a> 
    </li> 
     <?php $i++; 
     } 
    } ?> 
</ul> 

<!-- Tab Content --> 
<div class="tab-content clearfix"> 
    <?php 

     $home_categories = get_field("home_categories"); 
    // print_r($home_categories); 

     foreach($home_categories as $key => $home_cat) { 


      $term_id = $home_cat['categories']->term_id; 
      $term_name = $home_cat['categories']->name; 

      ?> 
      <div class="tab-pane fade<?php if ($key == 0) { echo ' in active'; }?>" id="tab-pane-<?php echo $key; ?>"> 
      <?php 


      $args = array(
       'post_type' => 'post', 
       'tax_query' => array(
        array(
         'taxonomy' => $term->taxonomy, 
         'terms' => array($term_id) 
        ) 
       ), 
       'posts_per_page' => 5, 
       'orderby' => 'date', 
       'order' => 'ASC', 
      ); 
      $query = new WP_Query($args); 

      foreach($query->posts as $post) { 

       ?> 

        <a href="<?php echo get_permalink($post->ID); ?>"><?php echo get_the_post_thumbnail($post->ID, 'thumbnail', array('class' => 'img-responsive img-thumbnail')); ?></a> 
        <a href="<?php echo get_permalink($post->ID); ?>"><h3><?php echo get_the_title($post->ID); ?></h3></a> 
        <?php the_excerpt(); ?> 
       <?php 


      } 

      ?> 
      </div> 
      <?php 



     }   ?> 

</div> 

だから、誰にも興味を持っている場合には、それはそれが最終的に達成してしまった方法です。

関連する問題