2015-08-24 33 views
0

我試圖在WordPress中使用高級自定義字段顯示3個不同位置的商店時間。當我用else if聲明取出整個中間部分時,它對另外兩個位置正常工作。只要我用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'); ?>:&nbsp;&nbsp;</b></p> 
      <?php if (get_sub_field('store_hours_closed') == "open") { ?> 
      <p class="hours-hours"> 
       <?php the_sub_field('store_hours_morning_time'); ?>&nbsp;am 
       - 
       <?php the_sub_field('store_hours_evening_time'); ?>&nbsp;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'); ?>:&nbsp;&nbsp;</b></p> 
      <?php if (get_sub_field('store_hours_closed') == "open") { ?> 
      <p class="hours-hours"> 
       <?php the_sub_field('store_hours_morning_time'); ?>&nbsp;am 
       - 
       <?php the_sub_field('store_hours_evening_time'); ?>&nbsp;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); ?>:&nbsp;&nbsp;</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); ?>&nbsp;am 
       - 
       <?php the_sub_field('store_hours_evening_time', $other_page); ?>&nbsp;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

是您的 「營業時間」 ACF領域的 「轉發」 字段? – Kory

回答

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'); ?>:&nbsp;&nbsp;</b></p> 
       <?php if (get_sub_field('store_hours_closed') == "open") : ?> 
        <p class="hours-hours"> 
         <?php the_sub_field('store_hours_morning_time'); ?>&nbsp;am 
         - 
         <?php the_sub_field('store_hours_evening_time'); ?>&nbsp;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'); ?>:&nbsp;&nbsp;</b></p> 
        <?php if (get_sub_field('store_hours_closed') == "open") : ?> 
        <p class="hours-hours"> 
        <?php the_sub_field('store_hours_morning_time'); ?>&nbsp;am 
        - 
        <?php the_sub_field('store_hours_evening_time'); ?>&nbsp;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); ?>:&nbsp;&nbsp;</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); ?>&nbsp;am 
          - 
          <?php the_sub_field('store_hours_evening_time', $other_page); ?>&nbsp;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; ?> 
+0

我知道它必須非常簡單。非常感謝你的幫助! –

+0

@TristanDespain樂於幫助,並歡迎來到Stack Overflow。如果此答案解決了您的問題,請將其標記爲已接受。謝謝! – Kory

0
You should mention type like option, page ,theme 

例子:

$other_page ='2';//pageid 
<?php if(get_field('store_hours', $other_page)): ?> 
相關問題