我有一個安裝了ACF轉發器字段的WordPress站點。我已經將視頻教程記錄下來,並嘗試了網站上的每個版本的模板代碼示例,但我什麼也得不到,什麼也沒有顯示。ACF轉發器字段沒有結果
我的轉發字段名稱'carousel_images',它有3個子字段,'圖像','標題'和'文本'。
任何人都可以幫忙嗎?我只想在主頁的前端顯示這些字段,這是一個使用'front-page.php'模板的靜態頁面。
我的代碼:
<?php if(get_field('carousel_images')): ?>
<div>
<?php while(has_sub_field('carousel_images')): ?>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></a>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
編輯1個 我的中繼器領域是一個自定義後類型裏面,所以我只好用WP_Query顯示自定義後類型之前,我試圖顯示中繼器領域。修改下面的工作代碼。
再次感謝。
<?php
$args = array(
'post_type' => 'home_carousel_image'
);
$the_query = new WP_Query($args);
?>
<!-- WP_Query WordPress loop -->
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php if(get_field('carousel_images')): ?>
<?php while(has_sub_field('carousel_images')): ?>
<div>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
感謝您的評論,但不幸的是,這也行不通,這裏沒有任何代碼顯示。我的中繼器字段是一個自定義帖子類型,它對任何事物都有影響嗎? – 2014-09-08 08:24:16
我現在工作,我不得不改變我的代碼,因爲中繼器字段是在自定義帖子類型中。謝謝。 – 2014-09-08 09:02:45
然後你應該接受答案,或者自己添加答案並接受(取決於哪個是真實的)。 – 2014-09-09 11:56:56