Display custom field only if value entered?
Hi all,
So I've created a custom field on my site that allows users to create a keyword, or (as it's called on my site) a "pet code" that is displayed directly under the ad title. But this field is not required. I only want the field to display on the ad if the user has entered a value for it, and I'm having trouble getting that "if" condition working properly.
Currently I have this in loop-ad_listing.php:
PHP Code:
<h3><a href="<?php the_permalink(); ?>"><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).'...'; else the_title(); ?></a></h3><br />
<?php if ( get_post_meta( $post->ID, 'cp_keyword', true ) ) ?><div class="petcode"><span><?php _e('Pet Code:', 'appthemes') ?></span> <?php echo get_post_meta( $post->ID, 'cp_keyword', true ); ?></div>
What do I need to change to make that field show up only if they have created a pet code? I'm not a php expert by any stretch of the imagination, so I know I'm just missing something here...
I know that if they don't enter a value then nothing will show up - I guess what I'm asking is how do I make it so that if they don't enter a value, the div.petcode won't display at all?
Oh, and the url of my site is
www.atascocitapets.org
Thanks!