Wordpress如果没有元场,那么这样做 - 怎么样?

时间:2011-02-18 15:26:31

标签: php wordpress

我在Wordpress中有以下代码,我正在显示元值,但如果没有填写,我想不显示该值。我将如何设置我的if / else?

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

1 个答案:

答案 0 :(得分: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做类似的事。