2016-10-19 6 views
0

高度なカスタムフィールドを使用してコンテンツを取り込むハイブリッドグリッドを作成しました。すべてがうまくいきますが、私がWordPressの管理者のACFで設定したチェックボックスに行くif/else文を設定すると、500エラーが発生します。これは、if/elseステートメントを持つメインコードブロックです。wordpressの高度なカスタムフィールドでPHPのelseif文が動作しない

<div class="watcheroos"> 
    <?php 

    if(count($postslist) > 0) { ?> 

    <ul class="list-unstyled"> 

    <?php 

     $clearfix_counter = 0; 

     foreach ($new_list as $index => $post) { 

     $bkg_id = get_post_thumbnail_id($post->ID); 
     $bkg_src = wp_get_attachment_image_src($bkg_id, 'medium'); 
     $bkg_src_lg = wp_get_attachment_image_src($bkg_id, 'large'); 

     $network = get_post_meta($post->ID,'network',true); 
     $timeofday = get_post_meta($post->ID,'time_of_day',true); 
     $date = get_post_meta($post->ID,'date',true); 
     $producer = get_post_meta($post->ID,'producer',true); 


     if($index %8 == 0 || $index %9 == 0 || $index == 1) { ?> 

      <?php if ($index == 0) { ?> 

       <li class="watcheroo first <?php if($addClass){echo 'widewidth'; } ?>" id="<?php echo sanitize_title($post->post_title); ?>"> 

        <div class="content" <?php if($bkg_src_lg[0]){ echo 'style="background-image: url(' . $bkg_src_lg[0] . ');"'; } ?> > 

        </div> 
        <div class="featured-info"> 
         <h4><?php echo $post->post_title; ?></h4> 
         <div class="info"> 
          <div class="network"><strong>Network:</strong> <?php echo $network; ?></div> 
          <div class="timeofday"><strong>Time-of-day:</strong> <?php echo $timeofday; ?></div> 
          <div class="date"><strong>Date:</strong> <?php echo $date; ?></div> 
          <div class="producer"><strong>Produced by:</strong> <?php echo $producer; ?></div> 
          <?php echo apply_filters('the_content', $post->post_content); ?> 
          <?php 
           $terms = get_the_terms($post->ID,'watcheroo_production_credits'); 
           if($terms) { 
            echo '<ul class="credits list-unstyled list-inline">'; 
            foreach ($terms as $term) { 
             echo '<li>' . $term->name . '</li>'; 
            } 
            echo '</ul>'; 
           } 
          ?> 
         </div> 
        </div> 

       </li> 



      <?php } elseif(get_field('wide_box')): { ?> 

       <li class="watcheroo wider" id="<?php echo sanitize_title($post->post_title); ?>"> 
        <div class="content" <?php if($bkg_src_lg[0]){ echo 'style="background-image: url(' . $bkg_src_lg[0] . ');"'; } ?> > 
         <div class="overlay"> 
          <div class="caption"> 
           <h4><?php echo $post->post_title; ?></h4> 
           <div class="info"> 
            <div class="network"><strong>Network:</strong> <?php echo $network; ?></div> 
            <div class="timeofday"><strong>Time-of-day:</strong> <?php echo $timeofday; ?></div> 
            <div class="date"><strong>Date:</strong> <?php echo $date; ?></div> 
            <div class="producer"><strong>Produced by:</strong> <?php echo $producer; ?></div> 
            <?php //echo apply_filters('the_content', $post->post_content); ?> 
           </div> 
          </div> 
         </div> 
        </div> 
        <div class="expanded-content"> 
         <?php echo apply_filters('the_content', $post->post_content); ?> 
         <?php 
          $terms = get_the_terms($post->ID,'watcheroo_production_credits'); 
          if($terms) { 
           echo '<ul class="credits list-unstyled list-inline">'; 
           foreach ($terms as $term) { 
            echo '<li>' . $term->name . '</li>'; 
           } 
           echo '</ul>'; 
          } 
         ?> 
        </div> 
       </li> 

      <?php } 

     } else { ?> 

      <li class="watcheroo <?php if($addClass){echo 'widewidth'; } ?>" id="<?php echo sanitize_title($post->post_title); ?>"> 
       <div class="content" <?php if($bkg_src[0]){ echo 'style="background-image: url(' . $bkg_src[0] . ');"'; } ?> > 
        <div class="overlay"> 
         <div class="caption"> 
          <h4><?php echo $post->post_title; ?></h4> 
          <div class="info"> 
           <div class="network"><strong>Network:</strong> <?php echo $network; ?></div> 
           <div class="timeofday"><strong>Time-of-day:</strong> <?php echo $timeofday; ?></div> 
           <div class="date"><strong>Date:</strong> <?php echo $date; ?></div> 
           <div class="producer"><strong>Produced by:</strong> <?php echo $producer; ?></div> 
           <?php //echo apply_filters('the_content', $post->post_content); ?> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="expanded-content"> 
        <?php echo apply_filters('the_content', $post->post_content); ?> 
        <?php 
         $terms = get_the_terms($post->ID,'watcheroo_production_credits'); 
         if($terms) { 
          echo '<ul class="credits list-unstyled list-inline">'; 
          foreach ($terms as $term) { 
           echo '<li>' . $term->name . '</li>'; 
          } 
          echo '</ul>'; 
         } 
        ?> 
       </div> 
      </li> 

     <?php } 

    } ?>  

    </ul> 

    <div class="clearfix"></div> 

     <?php } endif; ?> 

    </div> 

    </div> 

    <?php foreach ($postslist as $post) { 

     $network = get_post_meta($post->ID,'network',true); 
     $timeofday = get_post_meta($post->ID,'time_of_day',true); 
     $date = get_post_meta($post->ID,'date',true); 
     $producer = get_post_meta($post->ID,'producer',true); 
     $bkg_id = get_post_thumbnail_id($post->ID); 
     $bkg_src = wp_get_attachment_image_src($bkg_id, 'medium'); 

    ?> 

     <div id="<?php echo $post->ID . '-' . sanitize_title($post->post_title); ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalwindow"> 
    <div class="modal-dialog modal-lg"> 
     <div class="modal-content"> 
      <div class="modal-body"> 
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> 
     <?php if($bkg_src[0]){ ?><img class="alignleft" src="<?php echo $bkg_src[0]; ?>" /><?php } ?> 
     <h1 class="modal-title"><?php echo $post->post_title; ?></h1> 
     <div class="network"><strong>Network:</strong> <?php echo $network; ?></div> 
     <div class="timeofday"><strong>Time-of-day:</strong> <?php echo $timeofday; ?></div> 
     <div class="date"><strong>Date:</strong> <?php echo $date; ?></div> 
     <div class="producer"><strong>Produced by:</strong> <?php echo $producer; ?></div> 
     <?php echo apply_filters('the_content', $post->post_content); ?> 
     <div class="clearfix"></div> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 
    </div> 
    </div> 

    <?php } ?> 

私はendifを配置しています。間違った場所に?私は別の場所に配置しようとしました、どんな助けも間違いなく感謝されますようにしてください。

+2

基本ルールで両方の構文を使用していない:あなたは500を取得する場合、あなたが詳細については、Webサーバのエラーログを見て行きます。あなたがするまで、これはすべて無意味です。私たちは、問題が何であるかをGUESSに知らせるために、ワードプレスコード(発癌性が高く、既知の脳細胞毒素)の壁を通して読むつもりはありません。 –

+0

ugh ... endifs ..ログを読んだ後で、それらを適切な中カッコに置き換えることができます。 ifとendifは...特にこのようなコードでは非常に簡単に壊れています。 –

+0

PHP構文解析エラー:構文エラー、予期しない ':'行58の$ファイル内); –

答えて

1

PHPの条件文のための好適な構文:

if ($foo) { 
    do_something(); 
} elseif ($bar) { 
    do_something_else(); 
} else { 
    do_nothing(); 
} 

また一並ぶことができます。

if ($foo) do_something(); 
elseif ($bar) do_something_else(); 
else do_nothing(); 

これは、一般的に、しかし、良い習慣とはみなされません。

最後に、私はマニュアルから引用しますもう一つの代替構文:「ELSEIF」は、この代替構文で一つの単語でなければならないこと

if($a > $b): 
    echo $a." is greater than ".$b; 
elseif($a == $b): // Note the combination of the words. 
    echo $a." equals ".$b; 
else: 
    echo $a." is neither greater than or equal to ".$b; 
endif; 

注意。それはほとんど使われていない。

ただし、コードの1行、;-)

+1

これ以上時間がかかる場合は、 '' case' ](http://php.net/manual/en/control-structures.switch.php) –

+1

ありがとうございました。 – MikeL5799

関連する問題