警告:implode()[function.implode]:传递的参数无效

Sco*_*t B 19 php error-handling

我收到以下错误...

警告:implode()[function.implode]:在1335行的\ wp-content/themes/mytheme/functions.php中传递的参数无效

在...

function my_get_tags_sitemap(){
    if ( !function_exists('wp_tag_cloud') || get_option('cb2_noposttags')) return;
    $unlinkTags = get_option('cb2_unlinkTags'); 
    echo '<div class="tags"><h2>Tags</h2>';
    if($unlinkTags)
    {
        $tags = get_tags();
        foreach ($tags as $tag){
            $ret[]= $tag->name;
        }
        //ERROR OCCURS HERE
        echo implode(', ', $ret);
    }
    else
    {
        wp_tag_cloud('separator=, &smallest=11&largest=11');
    }
    echo '</div>';
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何拦截错误.该网站只有一个标签.

Mar*_*ich 45

您收到错误,因为$ret它不是数组.

要消除错误,请在函数开头使用以下行定义它: $ret = array();

似乎get_tags()调用没有返回任何内容,因此foreach没有运行,这意味着$ ret未定义.


小智 35

你可以试试

echo implode(', ', (array)$ret);
Run Code Online (Sandbox Code Playgroud)