[英]Advanced Custom Fields else if
I am trying to display store hours for 3 different locations with Advanced Custom Fields in WordPress. 我正在尝试使用WordPress中的高级自定义字段显示3个不同位置的商店营业时间。 When I take out the entire middle section with the else if statement, it works correctly for the other 2 locations.
当我使用else if语句取出整个中间部分时,它对于其他2个位置均正常工作。 As soon as I add in the section with the else if statement, the store hours go blank for all pages.
我在添加带有else if语句的部分后,所有页面的营业时间都变为空白。 Any help would be greatly appreciated.
任何帮助将不胜感激。 Here is what I have so far:
这是我到目前为止的内容:
First section 第一部分
<?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 -->
Second Section 第二部分
<?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 -->
Third Section 第三节
<?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 -->
It looks like you forgot a curly bracket or two in your code. 看起来您忘记了代码中的一两个花括号。 I went ahead and changed your if/else statements to use the alternative syntax, which you used in some places in the code block, but not consistently throughout.
我继续并更改了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
Example: 例:
$other_page ='2';//pageid
<?php if(get_field('store_hours', $other_page)): ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.