• My friend and I just started up a new site called Losemyself.com and are utilizing the WhosWho Theme developed by Elegant Themes. At this point we have begun putting up test posts and have been manually adding a custom field to place a Thumbnail on the frontpage of the site. Is there a way and if so, how to we add a code to place a default image for the thumbnail if no custom field is enabled for that post? i.e.:another writer/author posts something and forgets to add the thumbnail, because in this case, it messes up the formatting for the site and scrunches things together.

    Thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • check if the custom field has a value:

    <?php if(get_post_meta($post->ID,'customfieldkey',true)) {
    /*your image customfield code here*/
    } ?>
    <?php if(get_post_meta($post->ID,'customfieldkey',true)) {
    /*your image customfield code here*/
    } else {
    /*default image code here*/
    } ?>
    Thread Starter julesdr

    (@julesdr)

    Ok where do I find that code? Like which CSS File?

    Thread Starter julesdr

    (@julesdr)

    Ok I found something that looks like that code but it looks a lot more complicated (probably because of the theme I’m using…

    /* this function gets thumbnail from Post Thumbnail or Custom field or First post image */
    function get_thumbnail($width=100, $height=100, $class=”, $alttext=”, $titletext=”, $fullpath=false, $custom_field=”)
    {
    global $post, $shortname, $posts;

    $thumb_array[‘thumb’] = ”;
    $thumb_array[‘use_timthumb’] = true;
    if ($fullpath) $thumb_array[‘fullpath’] = ”; //full image url for lightbox

    if ( function_exists(‘has_post_thumbnail’) ) {
    if ( has_post_thumbnail() ) {
    $thumb_array[‘use_timthumb’] = false;

    $args=”;
    if ($class <> ”) $args[‘class’] = $class;
    if ($alttext <> ”) $args[‘alt’] = $alttext;
    if ($titletext <> ”) $args[‘title’] = $titletext;

    $thumb_array[‘thumb’] = get_the_post_thumbnail( $post->ID, array($width,$height), $args );

    if ($fullpath) {
    $thumb_array[‘fullpath’] = get_the_post_thumbnail( $post->ID );
    $thumb_array[‘fullpath’] = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $thumb_array[‘fullpath’], $matches);
    $thumb_array[‘fullpath’] = $matches[1][0];
    };
    }
    };

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to code a Default Thumbnail Image’ is closed to new replies.