2011-02-18 59 views
1

我在Wordpress中顯示元值的代碼如下,但如果它沒有填寫,我不想顯示該值。如何設置我的if/else在此?WordPress的如果沒有元字段,然後這樣做 - 如何?

<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); ?> 
         <div class="archive_images_one"><a href="<? echo $my_meta['image_one']; ?>" title="<? echo $my_meta['image_one_lightbox_title']; ?>" rel="lightbox"><img border="0" width="300px" height="200px" src="<? echo $my_meta['image_one']; ?>" alt="Android and iPhone App Development"></a></div> 
         <div class="archive_images_bottom"> 
          <div class="archive_images_bottom_one"><a href="<? echo $my_meta['image_two']; ?>" title="<? echo $my_meta['image_two_lightbox_title']; ?>" rel="lightbox" ><img border="0" width="100px" height="100px" src="<? echo $my_meta['image_two']; ?>" alt="Android and iPhone App Development"></a></div> 
          <div class="archive_images_bottom_two"><a href="<? echo $my_meta['image_three']; ?>" title="<? echo $my_meta['image_three_lightbox_title']; ?>" rel="lightbox"><img border="0" width="100px" height="100px" src="<? echo $my_meta['image_three']; ?>" alt="Android and iPhone App Development"></a></div> 
          <div class="archive_images_bottom_three"><a href="<? echo $my_meta['image_four']; ?>" title="<? echo $my_meta['image_four_lightbox_title']; ?>" rel="lightbox"><img border="0" width="100px" height="100px" src="<? echo $my_meta['image_four']; ?>" alt="Android and iPhone App Development"></a></div> 
         </div><!-- #archive_images_bottom --> 

回答

2
<?php if (!empty($my_meta) && !empty($my_meta['image_one'])): ?> 
    <div class="archive_images_one"><a href="<? echo $my_meta['image_one']; ?>" title="<? echo $my_meta['image_one_lightbox_title']; ?>" rel="lightbox"><img border="0" width="300px" height="200px" src="<? echo $my_meta['image_one']; ?>" alt="Android and iPhone App Development"></a></div> 
<?php endif; ?> 

做其他4

+0

TY類似這麼多!!!!! – HollerTrain 2011-02-18 16:25:41

相關問題