[英]Advanced Custom Fields else if
我正在嘗試使用WordPress中的高級自定義字段顯示3個不同位置的商店營業時間。 當我使用else if語句取出整個中間部分時,它對於其他2個位置均正常工作。 我在添加帶有else if語句的部分后,所有頁面的營業時間都變為空白。 任何幫助將不勝感激。 這是我到目前為止的內容:
第一部分
<?php if (is_single( 3823 ) ){ ?>
<section class="hours">
<h3>Outlet Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") { ?>
<b>Closed</b>
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
第二部分
<?php else if (is_single( 2284) ){ ?>
<section class="hours">
<h3>Builder Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") { ?>
<b>Closed</b>
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
第三節
<?php }
else { ?>
<?php $other_page = 47; ?>
<section class="hours">
<h3>Retail Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours', $other_page)): ?>
<?php while(has_sub_field('store_hours', $other_page)): ?>
<p class="days"><b><?php the_sub_field('store_hours_day', $other_page); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time', $other_page); ?> am
-
<?php the_sub_field('store_hours_evening_time', $other_page); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "closed") { ?>
Closed
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
看起來您忘記了代碼中的一兩個花括號。 我繼續並更改了if / else語句,以使用替代語法,您在代碼塊的某些位置使用了替代語法,但在整個過程中並不一致。
<?php if (is_single( 3823 ) ) : ?>
<section class="hours">
<h3>Outlet Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") : ?>
<b>Closed</b>
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php elseif (is_single( 2284) ) : ?>
<section class="hours">
<h3>Builder Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") : ?>
<b>Closed</b>
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php else : ?>
<?php $other_page = 47; ?>
<section class="hours">
<h3>Retail Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours', $other_page)): ?>
<?php while(has_sub_field('store_hours', $other_page)): ?>
<p class="days"><b><?php the_sub_field('store_hours_day', $other_page); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time', $other_page); ?> am
-
<?php the_sub_field('store_hours_evening_time', $other_page); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "closed") : ?>
Closed
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php endif; ?>
You should mention type like option, page ,theme
例:
$other_page ='2';//pageid
<?php if(get_field('store_hours', $other_page)): ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.