我正在尝试使用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 -->
答案 0 :(得分:0)
您的代码中似乎忘记了一两个大括号。我继续并改变了你的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; ?>
答案 1 :(得分:0)
You should mention type like option, page ,theme
示例:
$other_page ='2';//pageid
<?php if(get_field('store_hours', $other_page)): ?>