WordPress.org

Ready to get started?Download WordPress

Forums

How to hide empty custom field - post meta (2 posts)

  1. jumust
    Member
    Posted 2 years ago #

    Hi,
    I want to hide a custom field when it's empty. In the theme I'm using it is built like below:

    <?php
    
    if (have_posts()) : while (have_posts()) : the_post();
    
    	$image_thumb = get_post_meta(get_the_ID(), 'blog_thumb_image_url', true);
    ?>
    
    <div class="post_img">
    <img src="<?php echo get_bloginfo( 'stylesheet_directory' ); ?>/timthumb.php?src=<?php echo $image_thumb; ?>&h=300&w=600&zc=1" alt="" />
    							</div>

    I thought to move the <img> in the php function with an echo but really don't know how to do...Anyone knows it?

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    <?php
    if (have_posts()) : while (have_posts()) : the_post();
    if( get_post_meta(get_the_ID(), 'blog_thumb_image_url', true) ) :
    $image_thumb = get_post_meta(get_the_ID(), 'blog_thumb_image_url', true);?>
    <div class="post_img">
    <img src="<?php echo get_bloginfo( 'stylesheet_directory' ); ?>/timthumb.php?src=<?php echo $image_thumb; ?>&h=300&w=600&zc=1" alt="" />
    </div>
    <?php endif;?>

Topic Closed

This topic has been closed to new replies.

About this Topic