2016-08-17 59 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 –