2014-12-05 60 views
0

我目前使用ACF 5.我已經在產品類別上設置了中繼器。高級自定義字段產品類別中的中繼器(woocommerce)

我目前正在努力如何讓它輸出信息。我是acrhive產品循環內,並且我更新了以下模板包含被輸出內容:

<?php while (have_posts()) : the_post(); ?> 

    <?php wc_get_template_part('content', 'product_cat'); ?> 

<?php endwhile; // end of the loop. ?> 

在內容product_cat.php我已在每個循環的中繼以下。所有的基本信息已經顯示出來了,標題,woocommerce分類圖像等等。它是我添加到類別本身的中繼器,我無法展示。

<?php 
    $terms = get_field('attributes', 'product_cat_'.$term->term_id); 
    if($terms): ?> 
     <ul> 
    <?php foreach($terms as $term): ?> 
      <li> 
      <?php the_sub_field('attribute'); ?> 
      </li> 
    <?php endforeach; ?> 
     </ul> 
     <?php endif; ?> 

任何想法,將不勝感激

+0

你有'WP_DEBUG '啓用?你可能想要。至少,如果你有未定義的對象/變量,這可能會告訴你。你如何定義'$ term-> term_id'?我會從那裏開始,因爲如果沒有'term',你甚至不會進入'foreach()'循環。之後,我對ACF瞭解不夠。 – helgatheviking 2014-12-06 11:53:34

回答

0

打印出來ARGS第一:

<?php print_r($category);?> 

然後利用其輸出端產生如下:

<?php 
     $cat_id = $category->term_id; //used below to get a the acf from the categories! 
    ?> 


<?php 
     // $cat_id = $category->term_id; 

     $terms_features = get_field('features', 'product_cat_'.$cat_id); 
     if($terms_features): 
      // print_r($terms_features); 
     ?> 
     <ul> 
     <?php foreach($terms_features as $terms_feature): 
     // print_r($term); 
     ?> 
     <?php 
      $image_icon = $terms_feature['icon']; 
      $image_icon_show = $image_icon[sizes][large]; 
      // print_r($image_feature); 
     ?> 
       <li> 
        <img src="<?php echo $image_icon_show;?>" /> 
        <?php echo $terms_feature['description'];?> 
       </li> 
     <?php endforeach; ?> 
     </ul> 
     <?php endif; ?>