此代码:
$_post = &get_post($post->ID);
$classname = ($_post->iconsize[0] <= 128 ? 'small' : '') . 'attachment';
有时会产生此错误:
[Sun Apr 15 08:51:35 2012] [error] [client 180.76.5.150] PHP Notice: Undefined property: stdClass::$iconsize in /srv/www/virtual/myblog.com/htdocs/wp-content/themes/mimbo/attachment.php on line 8
我想修改该行以在属性上添加property_exists检查,如果它不存在则默认为''但是对于处理属性的语法有点不熟悉。线条怎么样?
答案 0 :(得分:1)
只需使用isset
:
if(isset($_post->iconsize)) {
// ...
}
所以:
<?php
$_post = &get_post($post->ID);
$classname = (isset($_post->iconsize) && $_post->iconsize[0] <= 128 ? 'small' : '') . 'attachment';
?>