【发布时间】:2010-08-23 16:01:29
【问题描述】:
我正在尝试创建一个侧边栏,我可以使用自定义字段在我的 wordpress cms 后端指定图像,现在我已经让它工作了,只有一个小错误,如果用户输入无效URL,图片链接会显示为损坏,不会显示,有没有办法可以隐藏损坏的图片图标?
我为父 DIV 元素设置了背景图像,这样如果没有图像要显示,父元素的背景就会显示。
这里是 PHP 代码:
//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;
}
提前谢谢!
【问题讨论】: