2017-07-25 106 views
0

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

下面是我用来创建与自定义类型后最近的职位转盘代码:

当我完全删除滑块下的所有工作PHP /负载,但我似乎并不能在代码中发现错误。

<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> 
+0

你是什么意思'所有其他的PHP'被阻止?你的error_log里有什么吗? – delboy1978uk

+0

例如<?php the_field('stalk-me'); ?>应显示您可以在后端添加的内容,但是它根本不显示任何内容。当我删除整个滑块时,会显示内容。 – imrafaelhi

+0

嗯。你有完整的脚本吗? – delboy1978uk

回答

2

你是压倒性的$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>'; 
     }; 

不知道这是否会解决其余的问题。它可能。
如果它没有至少你的代码会更清洁一点。

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

line 109 if(have_rows('skill-bars')将采取错误的$post你打破了。

+0

斑点! – delboy1978uk

+0

非常感谢!这确实有效。 我没有意识到覆盖$ post的可能影响,所以经验教训! – imrafaelhi

+0

也是一个选项。是使用[WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)。而不是array_chunck使用[modulo](https://alvinalexander.com/php/php-modulus-operator-syntax-examples) – janw