开发者

If no image, display text?

I'm having a problem finding a code that will display text (<?php blo开发者_如何学Cginfo('name'); ?>) when no image has been defined in the img src= (<?php echo get_option('to_logo'); ?>). This works in Firefox, of course, as a simple alt tag. But doesn't cut it in all browsers.

<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
</a>


Wouldn't it be simpler just to do something like:

<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?php
if (get_option('to_logo') != '') {
?>
    <img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
<?php
} else {
    echo bloginfo('name');
}
?>
</a>


This looks like WordPress. You can try to first test the image source to see if it is empty:

<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?=(get_option('to_logo')) ? '<img src="'.get_option('to_logo').'" title="Logo" alt="Logo" />' : 'The alternate text'; ?>
</a>


You can try this:

if (get_option('to_logo') == '') {
    echo bloginfo('name');
} else {
    echo get_option('to_logo');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜