我可以隐藏损坏的图像吗? [英] Can I hide broken images?
问题描述
我正在尝试创建一个侧边栏,我可以使用自定义字段在我的 wordpress cms 的后端为其指定图像,现在我已经让它工作了,只有一个小错误,如果用户输入无效URL,图片链接会显示为损坏的,不会显示,有什么办法可以隐藏损坏的图片图标吗?
我为父 DIV 元素设置了一个背景图像,这样如果没有要显示的图像,父元素的背景就会显示.
这是PHP代码:
//这里我得到了'side_image'自定义字段,它将包含侧面图像的URL如果 (have_posts()) :while (have_posts()) : the_post();$side = get_post_meta($post->ID, 'side_image', true);终了;万一;
HTML:
<!--这里是 HTML 标记--><div id="inner_content_right"><img src="<?php echo $side; ?>"/>
CSS:
#inner_content_right {背景: url(images/Layout_3_other_06_backup.jpg) 不重复;宽度:259px;高度:691px;浮动:对;位置:相对;底部:28px;}
提前谢谢!
你可以尝试类似的事情
<!--这里是 HTML 标记--><div id="inner_content_right"><img src="<?php if (@getimagesize($side)) echo $side; ?>"/>
I am trying to create a sidebar for which I can specify the image in the back-end of my wordpress cms using custom fields, now I have gotten it to work, with just one little bug, if the user enters a invalid URL, the image link will display as broken and will not display, is there a way that I can hide the broken image icon perhaps?
I have a background image set for the parent DIV element so that if there is no image to display, the parent's background will.
here is the PHP code:
//here I get the 'side_image' custom field, which will contain the URL to the side image
if (have_posts()) :
while (have_posts()) : the_post();
$side = get_post_meta($post->ID, 'side_image', true);
endwhile;
endif;
HTML:
<!--here is the HTML markup-->
<div id="inner_content_right">
<img src="<?php echo $side; ?>" />
</div>
CSS:
#inner_content_right {
background: url(images/Layout_3_other_06_backup.jpg) no-repeat;
width: 259px;
height: 691px;
float: right;
position: relative;
bottom: 28px;
}
Thanx in advance!
You could try something like
<!--here is the HTML markup-->
<div id="inner_content_right">
<img src="<?php if (@getimagesize($side)) echo $side; ?>" />
</div>
这篇关于我可以隐藏损坏的图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!