2014-01-09 61 views
0

我有這個代碼在一些頁面上顯示一個圖像,通過自定義metabox在wordpress頁面上傳。但是,我試圖弄清楚如何將它包裝在if/else語句中,以便如果用戶不上載圖像,則不顯示代碼。if/else聲明爲wordpress metabox

這裏是我的頁面模板代碼:

<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 --> 

回答

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 } ?> 

這應該是你正在尋找的條件。

+0

完美!謝謝!!試圖在它太複雜。我認爲這比我製作它容易 - 事實確實如此。再次感謝! – bcreative