• chudsf

    (@chudsf)


    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>
    <br><br>
    </span>
    <?php endif; ?>
  • The topic ‘PHP help — Skip code if Custom Field has no value’ is closed to new replies.