WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] show image if custom field present in the loop. (2 posts)

  1. Tom(dB)
    Member
    Posted 6 years ago #

    I have posts which are 'films', and posts which are 'news'.

    The film posts have a custom field which points to a preview image of the film.

    I would like to only display the image, on archive/category pages if the custom field is present.

    in english:

    start loop,
    lists posts - if it has custom field of 'thumbnail' then show "class - thumbnail".
    if not, don't show "class - thumbnail".
    continue with the loop.
    end loop.

    comprende? any help most appreciated.

  2. Tom(dB)
    Member
    Posted 6 years ago #

    After reading in other posts, and no one replying to this one ;) I have come up with the answer and thought I would post it to help others in my situation.

    <?php // shows thumbnail if custom field 'thumbnail' is present.
    $values = get_post_custom_values("thumbnail");
    if ( is_array($values) ) { ?>
    <img src="<?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?>"/>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic