有警告:
警告:/home/procsi/galina3000.ru/wp-content/themes/memoir/epanel/custom_functions.php在第112行上存在非法字符串偏移“ alt”
警告:/home/procsi/galina3000.ru/wp-content/themes/memoir/epanel/custom_functions.php中第113行的非法字符串偏移“标题”
代码如下所示:
if ( function_exists('has_post_thumbnail') ) {
if ( has_post_thumbnail( $post->ID ) ) {
$thumb_array['use_timthumb'] = false;
$args='';
if ($class <> '') $args['class'] = $class;
if ($alttext <> '') $args['alt'] = $alttext;
if ($titletext <> '') $args['title'] = $titletext;
$thumb_array['thumb'] = get_the_post_thumbnail( $post->ID, array($width,$height), $args );
if ($fullpath) {
$thumb_array['fullpath'] = get_the_post_thumbnail( $post->ID );
if ($thumb_array['fullpath'] <> '') {
$thumb_array['fullpath'] = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $thumb_array['fullpath'], $matches);
$thumb_array['fullpath'] = trim($matches[1][0]);
}
}
}
如何解决?谢谢。
答案 0 :(得分:0)
它试图告诉您,您正在使用字符串作为以字符串为键的数组:
$args='';
if ($class <> '') $args['class'] = $class;
if ($alttext <> '') $args['alt'] = $alttext;
if ($titletext <> '') $args['title'] = $titletext;
由于您首先声明$args
为字符串(''
),因此当您尝试为其分配其他参数时,这就是变量的类型。
如果您改为将其声明为数组-由于您希望将其用作数组,则它应该可以按预期工作:
$args = []; // or $args = array(); if PHP version < 5.4
if ($class <> '') $args['class'] = $class;
if ($alttext <> '') $args['alt'] = $alttext;
if ($titletext <> '') $args['title'] = $titletext;