簡體   English   中英

WordPress ACF轉發器字段循環

[英]Wordpress ACF repeater field loop

我試圖在我的wordpress主頁模板中循環出一個Repeater字段,但是由於某些原因,該div為空並且似乎無法正常工作。 我100%確定自己的代碼正確無誤,所以一定有問題。 任何人都知道可能是什么嗎?

這是我的循環的樣子,字段鍵正確! :)

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?> 

這就是我的front-page.php的樣子。 有趣的是,我之前在其他項目中使用過此工具,一切正常。 現在我的屏幕只是空白,我不知道發生了什么。

如果have_rows('field_56e7d8bebb545')確實為true,請調試the_row();

var_dump(the_row());

您可以查看the_result,如果為空,則可能必須為have_row($ field_name, $ post_id )設置第二個參數

嘗試這個..,因為您還沒有打印出任何可以在瀏覽器中顯示的東西。.您僅向div提供了data屬性。

在內部HTML中寫一些東西可能會看到您的中繼器值

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"><?php the_sub_field('image'); ?></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?> 

field_56e7d8bebb545是字段關鍵字,而不是字段名稱。 字段名稱必須在have_rows()函數中使用。 可以在標簽旁邊的“高級自定義字段”屏幕上找到-

在此處輸入圖片說明

暫無
暫無

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

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