Conditional Custom Field – Meta Display


Hi, I have a question. Which is the best way / most efficient way to display conditional custom field / meta data in a custom "single.php" for post display?

1

<?php $someValue = get_post_meta( $post->ID, '_text_field_weight', true );

if(!($someValue == null || $someValue == '')){
    echo "<li>Weight: <strong>{$someValue} Ct</strong>.</li>";
}
?>

2

<?php $meta_value = get_post_meta( $post->ID, 'website', true ); 
            if  (!empty( $meta_value )) {echo '<a href="' . $meta_value . '">The Website Link</a>';}
            else {} ?>

3

<?php if ( get_post_meta( get_the_ID(), 'thumb', true ) ) : ?>
    <a href="<?php the_permalink() ?>" rel="bookmark">
        <img class="thumb" src="<?php echo esc_url( get_post_meta( get_the_ID(), 'thumb', true ) ); ?>" alt="<?php the_title_attribute(); ?>" />
    </a>
<?php endif; ?>

4 Or there is a better way works best with beans?

Thanks for your input!

Write a reply

Login or register to write a reply, it's free!