Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP代码,用于在未填充自定义字段时显示备用图像_Php_Image_Wordpress_Placeholder_Custom Fields - Fatal编程技术网

PHP代码,用于在未填充自定义字段时显示备用图像

PHP代码,用于在未填充自定义字段时显示备用图像,php,image,wordpress,placeholder,custom-fields,Php,Image,Wordpress,Placeholder,Custom Fields,如果没有提供图像自定义字段,我试图显示可能被称为占位符图像的内容 我已经走了这么远,但有点卡住了。输出显示代码。这是我正在使用的PHP $my_image = get_post_meta($post->ID, 'ecpt_images', true); if( isset($my_image) && $my_image != '') { echo '<img src="'.$my_image.'" width="230px" height="175px" /

如果没有提供图像自定义字段,我试图显示可能被称为占位符图像的内容

我已经走了这么远,但有点卡住了。输出显示代码。这是我正在使用的PHP

$my_image = get_post_meta($post->ID, 'ecpt_images', true);

if( isset($my_image) && $my_image != '') {
    echo '<img src="'.$my_image.'" width="230px" height="175px" />';
} else { 
    echo '<img src="/wp-content/uploads/2013/02/Poor.png">';
}
$my\u image=get\u post\u meta($post->ID,'ecpt\u images',true);
if(设置($my_image)&&$my_image!=''){
回声';
}否则{
回声';
}

提前非常感谢

检查您是否使用了短开放标签
。默认情况下,此设置已禁用,不建议使用。确保将代码正确地包装在

中,是否确保将PHP代码包装在
中?请澄清
输出显示代码的意思
尝试重写if语句,如if strlen($myimg)>0,假设图像路径正确且存在,IMO的更好方法是使用带有css背景图像的容器元素(如果存在实际图像,则会将其隐藏)。这甚至可能有助于解决你的问题(例如,我不完全理解实际问题是什么)。