Bootstrap Post 轮播阻塞页面模板中的其他 PHP

Bootstrap Post Carousel blocking other PHP in page-template

我在 WordPress 页面模板中创建了一个 post 轮播,但所有其他 PHP(例如高级自定义字段内容等)都被阻止了。 wp_debug 没有显示错误,我在代码中找不到任何错误。

下面是我用来创建最近 post 自定义 post 类型轮播的代码:

当我完全删除滑块下面的所有 PHP 时,它会 work/load,但我似乎找不到代码中的错误。

<div class="carousel-inner" role="listbox">
<?php
    $i = 2; 
    global $post; 
    $args = array( 
            'numberposts'       => -1,
            'post_type'         => 'work',
            'orderby'           => 'date',
            'order'             => 'ASC',
    );
    $myposts = get_posts($args);
    if($myposts):
          $chunks = array_chunk($myposts, $i);
          $html = "";
          foreach($chunks as $chunk) {
            ($chunk === reset($chunks)) ? $active = "active" : $active = "";
            $html .= '<div class="item '.$active.'">';
            foreach($chunk as $post) {
              $html .= '<div id="timeline-item" class="col-lg-6 col-md-6 col-sm-6 col-xs-6"><div><h6 style="text-align: left;">';
              $html .= get_the_date('Y');
              $html .= '</h6><h2 style="text-align: left;">';
              $html .= get_the_title();
              $html .= '</h2><p style="text-align: left;">';
              $html .= get_post_field('post_content');
              $html .= '</p></div></div>';
            };
            $html .= '</div>';                
            };
          echo $html;             
        endif;
?>
</div>

您正在覆盖 $post。在 WordPress 从不 覆盖 $post
尝试更换这部分。

foreach($chunk as $slide) {
          $html .= '<div id="timeline-item" class="col-lg-6 col-md-6 col-sm-6 col-xs-6"><div><h6 style="text-align: left;">';
          $html .= get_the_date('Y', $slide);
          $html .= '</h6><h2 style="text-align: left;">';
          $html .= get_the_title($slide);
          $html .= '</h2><p style="text-align: left;">';
          $html .= get_post_field('post_content', $slide);
          $html .= '</p></div></div>';
        };

不确定这是否能解决其余问题。有可能。
如果没有,至少你的代码会更干净一些。

编辑 看到完整的脚本,这很可能是问题所在。

第 109 行 if( have_rows('skill-bars') 会接受你弄错的 $post