首页 文章

PHP警告:implode():传递的参数无效

提问于
浏览
1

我每次访问我的wordpress网站时都会在apache日志中收到此警告:

[error] [client myiphere] PHP警告:implode():在第16行的/var/www/mysitepath/wp-content/themes/mytheme/noscript/views/list-view.php中传递的参数无效,参考文献:http ://www.example.com/

这是list-view.php的一部分:

<?php
$mytheme = mytheme::getInstance();
$currentContentLayout = $mytheme->WPData['currentContentLayout'];
$contentLayout = $mytheme->settings->contentLayouts->{$currentContentLayout};
$headerClasses = array();
if('no' == $contentLayout->metaPosition){
    $headerClasses = 'no-meta';
} else {
    $headerClasses[] = 'meta-' . $contentLayout->metaPosition;
}
?>
<div class="mytheme-list-view row">
    <div class="large-12 columns">
        <?php while(have_posts()){ the_post();?>
        <article id="post-<?php the_ID();?>" <?php post_class();?> data-mytheme-post-from-id="<?php the_ID();?>">
            <header class="entry-header <?php echo implode(' ', $headerClasses);?>">
...
...

代码有什么问题吗?谢谢

2 回答

  • 5

    您需要更改此行:

    $headerClasses = 'no-meta';
    

    对此:

    $headerClasses[] = 'no-meta';
    

    $headerClasses 是字符串时会发生此问题,因为 implode() 将数组作为第二个参数 .

  • 1

    implode 函数需要 array 作为参数,而在if条件下,您传递简单字符串 . 你这样使用shuld

    if('no' == $contentLayout->metaPosition){
        $headerClasses[] = 'no-meta';              // this should be pass into array
    } else {
        $headerClasses[] = 'meta-' . $contentLayout->metaPosition;
    }
    

    第二个 . 你可以检查这样的impload

    <?php echo is_array($headerClasses)? implode(' ', $headerClasses):$headerClasses;?>
    

相关问题