WordPress.org

Support

Support » Themes and Templates » [Resolved] show image if custom field present in the loop.

[Resolved] show image if custom field present in the loop.

  • deadlyhifi
    Member

    @tomdebruin

    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.

Viewing 1 replies (of 1 total)
  • deadlyhifi
    Member

    @tomdebruin

    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 } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] show image if custom field present in the loop.’ is closed to new replies.