2016-08-17 55 views
-2

嗨在wordpress中使用不同的語言做一些代碼,但它沒有在elseif的某處工作,有人可以幫我嗎?意外elseif在wordpress主題

 <?php 
      if(ICL_LANGUAGE_CODE=='en'): 
      $loop = new WP_Query(array( 
       'post_type' => 'shapes_en', 
       'posts_per_page' => -1, 
       'orderby' => 'menu_order', 
       'order' => 'asc', 
       ) 
      ); 
      if ($loop): 
      while ($loop->have_posts()) : $loop->the_post(); 
      elseif(ICL_LANGUAGE_CODE=='he'): 
      $loop = new WP_Query(array( 
       'post_type' => 'shape', 
       'posts_per_page' => -1, 
       'orderby' => 'menu_order', 
       'order' => 'asc', 
       ) 
      ); 
      if ($loop): 
      while ($loop->have_posts()) : $loop->the_post(); 
      endif; 
      ?> 
      <li> 
       <a href="<?php the_permalink()?>"><?php the_post_thumbnail('idustry-thumbnail'); ?></a> 
       <h3><a href="<?php the_permalink()?>"><?php the_title()?></a></h3> 
      </li> 
      <?php endwhile; 
      endif;?> 
+0

「不起作用」是什麼意思?你需要更具體。 –

+0

您需要插入'endwhile;'語句。 –

+0

解析錯誤:語法錯誤,意外的'elseif'(T_ELSEIF)位於/home/darplast/public_html/wp-content/themes/darplast/index.php第20行 –

回答

0

while:語法要求一個endwhile;,否則while塊停止在那裏是不知道。由於endwhile;聲明的缺失,PHP認爲elseif;仍在while循環內,因此elseif;是意外的。

The docs

In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

你的代碼改成這樣:

if ($loop): 
    while ($loop->have_posts()): 
     $loop->the_post(); 
    endwhile; 
elseif (ICL_LANGUAGE_CODE == 'he'): 
... 

如果使用另一種語法編寫模板時,需要我不知道,但除非你正在編寫一個模板,我建議使用正常的語法與冰壺括號,因爲它通常更容易閱讀。

if ($loop) { 
    while ($loop->have_posts()) { 
     $loop->the_post(); 
    } 
} 
elseif (ICL_LANGUAGE_CODE == 'he') { 
... 
+0

現在,他給我寫了 –

+0

解析錯誤:語法錯誤,意外的文件結尾在/home/darplast/public_html/wp-content/themes/darplast/index.php在線55 –