簡體   English   中英

ACF轉發器字段顯示

[英]ACF Repeater field Display

我創建了一個名為“產品”的自定義帖子類型,並在名為“成分”的帖子類型中創建了一個自定義分類法。

我添加了一個稱為“ ingredients-INCI”的轉發器字段和一個“ ingredients-INCI-group”的子字段,該子字段將分類法中的值稱為“成分”。

自定義中繼器字段截圖:

單擊以查看自定義中繼器字段屏幕截圖

每個產品都有很多成分,我想顯示該產品選擇的成分的列表。 這是我的模板代碼:

 <?php /** PostType Page Template: Product */ get_header(); ?> <div id="b_primary" class="b_content-area"> <main id="b_main" class="b_site__main" role="main"> <?php while ( have_posts() ) : the_post(); ?> <!-- START product information --> <div class="toptext">If you have any enquiries, please click here to contact us.</div> <div class="toptext">Please ensure you include all the products information that you wish to enquire about.</div> <div class="tableproduct"> <table> <tr> <th><div class="tabletitle">PRODUCT NAME</div></th> <th><div class="tableresult"><?php wp_title(); ?></div></th> </tr> <tr> <td><div class="tabletitle">PRODUCT DESCRIPTION</div></td> <td><div class="tableresult"><?php the_field('product_description'); ?></div></td> </tr> <tr> <td><div class="tabletitle">BRAND</div></td> <td><div class="tableresult"><?php the_field('brand'); ?></div></td> </tr> <tr> <td><div class="tabletitle">BARCODE</div></td> <td><div class="tableresult"><?php the_field('barcode'); ?></div></td> </tr> <tr> <td><div class="tabletitle">Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Ingredients are listed in decreasing order of quantity.</div></div></td> <td><div class="tableresult"> <?php // check if the repeater field has rows of data if( have_rows('ingredients-INCI') ): // loop through the rows of data while ( have_rows('ingredients-INCI') ) : the_row(); // display a sub field value the_sub_field('ingredients-INCI-group'); endwhile; else : // no rows found endif; ?> </div></td> </tr> <tr> <td><div class="tabletitle">Fragrance Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Fragrance Ingredients are those which require listing under EC648/2004 on detergents.</div></div></td> <td><div class="tableresult"> RESULTS HERE </div></td> </tr> </table> <div class="tabletitleother">OTHER INFORMATION</div> <div class="tableotherresults">The above formulation is for products manufactured between <?php the_field('date_from'); ?> and <?php the_field('date_to'); ?></div> <div class="tableyellow">INCI / CAS / Ingredient information CLICK HERE or HERE</div> </div> <!-- END product information --> <?php endwhile; // End of the loop. ?> </main><!-- #b_main --> </div><!-- #b_primary --> <?php get_sidebar(); ?> <?php get_footer(); ?> 

此代碼似乎破壞了輸出。 請幫忙!

你可以試試看

$productField = get_field('ingredients-INCI');

所有轉發器字段都將在此“ $ productField”變量中列出。

foreach($productField as $product){
   echo $product['ingredients-INCI-group'];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM