我在开发模式中得到了以下警告:
警告:join():在/webDir/project/wp includes/post模板中传递的参数无效。php在线371
在生产模式中<article>
类属性变为空(class=""
).此错误对应于下一个函数:
/**
* Display the classes for the post div.
*
* @since 2.7.0
*
* @param string|array $class One or more classes to add to the class list.
* @param int|WP_Post $post_id Optional. Post ID or post object.
*/
function post_class( $class = \'\', $post_id = null ) {
// Separates classes with a single space, collates classes for post DIV
echo \'class="\' . join( \' \', get_post_class( $class, $post_id ) ) . \'"\';
}
经过一段时间的调试,我在下一个自定义函数(functions.php)中发现了问题:
/* Remove hentry class from "contact" page */
if(! function_exists( \'remove_hentry\' )) {
function remove_hentry( $classes ) {
$classes[] = customTheme_layout_class();
if(is_page(\'contact\')) {
$classes = array_diff($classes, array("hentry"));
return $classes;
}
}
add_filter( \'post_class\', \'remove_hentry\' );
}
删除这些行后,警告将消失
<article>
类别显示正确。
customTheme_layout_class()
是具有下一个代码的主题函数:
/* ------------------------------------------------------------------------- *
* Template functions
/* ------------------------------------------------------------------------- */
/* Layout class
/* ------------------------------------ */
if ( ! function_exists( \'customTheme_layout_class\' ) ) {
function customTheme_layout_class() {
// Default layout
$layout = \'col-3cm\';
$default = \'col-3cm\';
// Check for page/post specific layout
if ( is_page() || is_single() ) {
// Reset post data
wp_reset_postdata();
global $post;
// Get meta
$meta = get_post_meta($post->ID,\'_layout\',true);
// Get if set and not set to inherit
if ( isset($meta) && !empty($meta) && $meta != \'inherit\' ) { $layout = $meta; }
// Else check for page-global / single-global
elseif ( is_single() && ( ot_get_option(\'layout-single\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-single\',\'\'.$default.\'\');
elseif ( is_page() && ( ot_get_option(\'layout-page\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-page\',\'\'.$default.\'\');
// Else get global option
else $layout = ot_get_option(\'layout-global\',\'\'.$default.\'\');
}
// Set layout based on page
elseif ( is_home() && ( ot_get_option(\'layout-home\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-home\',\'\'.$default.\'\');
elseif ( is_category() && ( ot_get_option(\'layout-archive-category\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-archive-category\',\'\'.$default.\'\');
elseif ( is_archive() && ( ot_get_option(\'layout-archive\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-archive\',\'\'.$default.\'\');
elseif ( is_search() && ( ot_get_option(\'layout-search\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-search\',\'\'.$default.\'\');
elseif ( is_404() && ( ot_get_option(\'layout-404\') !=\'inherit\' ) ) $layout = ot_get_option(\'layout-404\',\'\'.$default.\'\');
// Global option
else $layout = ot_get_option(\'layout-global\',\'\'.$default.\'\');
// Return layout class
return $layout;
}
}
知道我的自定义函数有什么错误吗(
remove_hentry
)?