求大神点解。
页面提示说:“Warning: implode(): Invalid arguments passed in /home/tumuneco/public_html/wp-content/themes/verge/carousel.php on line 8”
但是我不懂php,搞不懂改怎么修改

解决方案 »

  1.   

    图好像有点小,具体代码如下:
    <?php global $option_setting;
    $count = 1;
    if (isset($option_setting['carousel-enable-on-home'])) :
    if( $option_setting['carousel-enable-on-home'] && (is_front_page() || is_home() )) :  ?>
        <div id="carousel-wrapper" class="container">
        <ul class="bxcarousel">
         <?php
         $args = array( 'posts_per_page' => $option_setting['carousel-count'], 'category' => implode(",",$option_setting['carousel-cats']) );
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ) :
      setup_postdata( $post ); ?>
       <li><a title="<?php the_title(); ?>" href='<?php the_permalink(); ?>'>
       <?php if (has_post_thumbnail()) : 
    $thumb_id = get_post_thumbnail_id();
    $thumb_url = wp_get_attachment_image_src($thumb_id,'carousel', true);
    echo "<img class='carousel-image' src='".$thumb_url[0]."' title='".get_the_title()."'>";
    else :
    echo "<img class='carousel-image' src='".get_template_directory_uri()."/assets/images/placeholder2.jpg' title='".get_the_title()."'>";
    endif; ?></a></li>
    <?php endforeach; 
    wp_reset_postdata(); 
    ?>            
         </ul>   
    </div>
        
    <?php endif;
    endif;?>
      

  2.   

    错误原因:
    $option_setting['carousel-cats']不是数组  
    需要打印出来是什么类型
      

  3.   

    var_dump($option_setting);输出来是什么?
      

  4.   

    var_dump(isset($option_setting['carousel-cats']));
    print_r($option_setting['carousel-cats']);看看是否為空。
      

  5.   


    $args = array( 'posts_per_page' => $option_setting['carousel-count'], 'category' => implode(",",$option_setting['carousel-cats']) );
    改为:$category = isset($option_setting['carousel-cats'])? implode(",",$option_setting['carousel-cats']) : '';
    $args = array( 'posts_per_page' => $option_setting['carousel-count'], 'category' => $category );
      

  6.   


    $args = array( 'posts_per_page' => $option_setting['carousel-count'], 'category' => implode(",",$option_setting['carousel-cats']) );
    改为:$category = isset($option_setting['carousel-cats'])? implode(",",$option_setting['carousel-cats']) : '';
    $args = array( 'posts_per_page' => $option_setting['carousel-count'], 'category' => $category );这样就可以避免为空出现警告了。