0

我在某些页面上有此代码,以显示通过 wordpress 页面上的自定义元框上传的图像。但是,我试图弄清楚如何将其包装在 if/else 语句中,以便如果用户不上传图像,则不会显示代码。

这是我在页面模板上的代码:

<div id="image-slider" class="rs-full">
    <div class="container">
        <div class="row-fluid">
            <img src="<?php global $post; $image = get_post_meta( $post->ID, '_wpb_rs_full', true ); echo $image; ?>" alt="<?php echo get_the_title($ID); ?>">
                    </div> <!-- /.row-fluid -->
    </div><!-- /.container -->
</div><!-- /#image-slider -->
4

1 回答 1

0
<?php
global $post; 
$image = get_post_meta( $post->ID, '_wpb_rs_full', true );

if($image){ ?>
    <img src="<?php echo $image; ?>" alt="<?php echo get_the_title($ID); ?>">
<?php } ?>

这应该是您正在寻找的条件。

于 2014-01-09T18:31:59.593 回答