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

时间:2015-04-27 13:02:03

标签: php wordpress logging implode

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

  

[error] [client myiphere] PHP警告:implode():在第16行的/var/www/mysitepath/wp-content/themes/mytheme/noscript/views/list-view.php中传递的参数无效,referer :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 个答案:

答案 0 :(得分:5)

您需要更改此行:

$headerClasses = 'no-meta';

对此:

$headerClasses[] = 'no-meta';

$headerClasses是字符串时会出现问题,因为implode()将数组作为第二个参数。

答案 1 :(得分:1)

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

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;?>
相关问题