The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

PHP help -- Skip code if Custom Field has no value (1 post)

    Posted 9 years ago #

    Hello there. I'm using custom fields to display information about press clippings. I've got four -- date, publication, PDF, and Link.

    I have the template spit out a little PDF icon linking to the PDF version and the text "LINK" linking to the online version of a clipping.

    This is working wonderfully, but some of my clippings do not have either a PDF version or a link, and these fields are empty. The template then generates an icon/link that links to nothing. How can I get this code to skip the custom field if it is empty?

    My code:

    <?php if ( in_category('3') ): ?>
    <span class="caps" style="font-size: 8pt">
    >>Published <?php echo get_post_meta($post->ID, 'Date', true); ?> in <?php echo get_post_meta($post->ID, 'Publication', true); ?>.
    <a href="<?php echo get_post_meta($post->ID, 'PDF', true); ?>"><img src="/images/pdficon.gif" border="0"></a>
    <a href="<?php echo get_post_meta($post->ID, 'Link', true); ?>">LINK</a>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic