我的新客户有一个很久没有更新的网站。现在,PHP版本,wordpress版本和插件都是最新的,但是Portifolio项目现在返回此错误:
屏幕截图:
警告:非法字符串偏移“ alt”位于 /home/elite856/public_html/wp-content/themes/eliteled/functions.php在 679行
警告:输入中非法的字符串偏移量'url' /home/elite856/public_html/wp-content/themes/eliteled/functions.php在 679行
这是第679行:
'<img src="'. $ob_img['url'] .'" class="capa" alt="'. $ob_img['alt'] .'" />'.
这是整个功能:
$portfolio = new WP_Query( $args );
if( $portfolio->have_posts() ){
while ( $portfolio->have_posts() ) { $portfolio->the_post();
$ob_img = get_field( 'imagem_de_capa' );
$allcats = get_the_category( get_the_ID() );
$cat = $allcats[0]->name;
$arrayData = array(
'id' => get_the_ID(),
'Titulo' => get_the_title(),
'cat' => $cat
);
//Criando arrayData com as informações do portfolio
if( have_rows('conteudo_do_portfolio') ){
while( have_rows('conteudo_do_portfolio') ){ the_row();
$tipo = get_field( 'tipo' );
if( $tipo == 'foto' ){
if( empty( $arrayData['imgs'] ) ){
$arrayData['imgs'][] = array(
'full' => $ob_img['original_image']['url'],
'thumb' => wp_get_attachment_image_src( $ob_img['id'], 'thumb_portfolio' )[0]
);
}
$idImg = get_sub_field('foto');
$arrayData['imgs'][] = array(
'full' => wp_get_attachment_image_src( $idImg, 'full' )[0],
'thumb' => wp_get_attachment_image_src( $idImg, 'thumb_portfolio' )[0]
);
}else{
$idVideo = youtube_video_id( get_sub_field('video') );
$arrayData['imgs'][] = array(
'full' => $idVideo,
'thumb' => "http://img.youtube.com/vi/{$idVideo}/0.jpg"
);
}
}
}
//'<li class="'. ( is_home() || is_front_page() ? 'item-home' : '' ) .'">'
$conteudo .= '<li>'.
'<img src="'. $ob_img['url'] .'" class="capa" alt="'. $ob_img['alt'] .'" />'.
'<div class="camada text-center">'.
'<a href="#" class="openModalPortfolio" data-tipo="'. get_field( 'tipo' ) .'" data-json=\''. json_encode( $arrayData ) .' \'\ >'.
//'<div class="'. ( is_home() || is_front_page() ? 'center-home' : 'center' ) .'">'.
'<div class="center">'.
//'<img src="/wp-content/themes/eliteled/images/expand'. ( is_home() || is_front_page() ? '' : '-red' ) .'.png" class="expand" />'.
'<img src="/wp-content/themes/eliteled/images/expand-red.png" class="expand" />'.
'<span class="titulo">'. ( strlen( get_the_title() ) > 60 ? substr( get_the_title(), 0, 60 ) . '...' : get_the_title() ) .'</span>'.
'<span class="cat">'. $cat .'</span>'.
'</div>'.
'</a>'.
'</div>'.
'<div class="camada camada-branca"></div>'.
'</li>';
}
}
我已经阅读到该警告以前不会像PHP 5.4之前那样被打印出来,并且它的发生是因为它是期望值和数组。我的PHP技能不高,有人可以给我一个做什么的线索吗?
答案 0 :(得分:0)
根据转储的数据,我猜测original_image
的内容是附件ID,请尝试以下操作:
$img_params = json_decode($ob_img, true); // convert string to associative array
$url = wp_get_attachment_image_url($img_params['original_image']);
if ($url) {
// we have the image url now so display the image here tag here
}
如果它不起作用,请检查原始主题/插件开发人员是否有该产品组合来源的插件/主题的新更新