2016-08-17 1 views
-2

안녕하세요. 언어 변경이있는 WordPress에서 일부 코드를 작성하고 있지만 elseif의 어딘가에서 문제를 해결하지 못해서 제발 저를 도울 수 있습니까?wordpress 주제에 대한 예상치 못한 elseif

 <?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 on line 20 –

답변

0

while: 구문 while 블록 정거장 그렇지 않으면 알 수없는, endwhile; 요구한다. 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 행의 예기치 않은 파일 끝에 도달했습니다. –