我正在创建一个短代码来显示不同大小的图像:大、小和常规。用户可以选择设置large="true"
或small="true"
在编写短代码以输出正确的图像代码时。
当短代码处于活动状态时,我在前端遇到了一个PHP问题,下面的消息是large
和/或small
未设置为true或false:
注意:未定义索引:大in/wp-content/themes/mysite/functions。php在线1449
注意:未定义的索引:在/wp content/themes/mysite/functions中较大。php在线1451
第1449行为if( $atts[\'large\'] == true )
1451号线是if( $atts[\'small\'] == true )
以下是短代码的PHP代码:
add_shortcode ("img", "img_output");
function img_output($atts, $content="null") {
extract( shortcode_atts( array(
\'large\' => false,
\'small\' => false,
\'url\' => \'\'
), $atts ));
if( $atts[\'large\'] == true ) {
return \'<img src="\' . $url . \'" class="img-large" width="100%" height="auto" />\';
} else if( $atts[\'small\'] == true ) {
return \'<img src="\' . $url . \'" class="img-small" width="100%" height="auto" />\';
} else {
return \'<img src="\' . $url . \'" class="img-regular" width="100%" height="auto" />\';
}
}
任何帮助都将不胜感激,谢谢!