Wordpress"警告:缺少参数2"错误

时间:2015-03-17 19:54:37

标签: wordpress compiler-errors

我有两个超级特定的'缺失参数2'错误正在进行中。在localhost中它一切都很好,但是一旦我把整个东西放在网上它就会返回这些错误:

A)警告:第89行/home/content/23/9090823/html/extranet/printedcrush/wp-content/themes/facepress/functions.php中的add_category_to_single()缺少参数2

代码:

add_filter('body_class','add_category_to_single');
    (line 89) function add_category_to_single($classes, $class) {
        if (is_single() ) {
            global $post;
            foreach((get_the_category($post->ID)) as $category) {
                $classes[] = $category->category_nicename;
            }
        }
    return $classes;
}

B)警告:第100行/home/content/23/9090823/html/extranet/printedcrush/wp-content/themes/facepress/functions.php中的my_class_names()缺少参数2

代码:

add_filter('body_class','my_class_names');
    (line 100) function my_class_names($classes, $class) {
    if (is_single() ) {
        global $post;
        foreach((get_the_category($post->ID)) as $category) {
            $classes[] = $category->category_nicename;
        }
    }       
    if (! ( is_user_logged_in() ) ) {
        $classes[] = 'logged-out';
    }
    return $classes;
}

有人知道我怎么能修复这些错误? 提前致谢。 :)

1 个答案:

答案 0 :(得分:2)

body_class过滤器钩子接受一个单独的参数,即要修改的类数组,例如:

add_filter( 'body_class', 'so29108478_body_class' );
function so29108478_body_class( $classes ) {
    $classes[] = 'my-class';
    return $classes;
}

http://codex.wordpress.org/Plugin_API/Filter_Reference/body_class