• Is it possible to create a loop, that does something similar to this:

    if
    [customfield-value] is not empty
    then
    insert image src: ../images/customfield-value.jpg
    else
    insert image src: ../images/default.jpg
    end

    Narrowing it down to questions:
    1. can i make the custom field part of my img src path?
    2. my custom field value will be containing spaces – will that result in a problem?

    Eksample: I have a custom field with the value of a name etc “John Smith”, i have manually uploaded a thumbnail picture to my server (../images/) called “John Smith.jpg”, now i want to display that picture. However if the custom field does not contain a name (=null), then i just want to display a default thumbnail (..images/default.jpg).

    Hope it makes sense and that some of you guys can help me ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter j4ze

    (@j4ze)

    So far i’ve come up with this code

    <?php if get_post_meta( $post->ID, 'CUSTOMFIELD', true)!=null {
    				<div id="authThumb"><img src="../fluxichild/images/<?php echo get_post_meta( $post->ID, 'CUSTOMFIELD', true );?>.jpg"/></div>
    				}else {
    					div id="authThumb"><img src="../fluxichild/images/defaultAuth.jpg" /></div>
    				}
    				?>

    but to no surprise, it doesn’t work, I know i have a syntax error somewhere, but i hardly think thats the only mistake ??

    corrected for syntax errors:

    <?php if( get_post_meta( $post->ID, 'CUSTOMFIELD', true)!=null ) { ?>
    				<div id="authThumb"><img src="../fluxichild/images/<?php echo get_post_meta( $post->ID, 'CUSTOMFIELD', true ); ?>.jpg"/></div>
    				<?php } else { ?>
    					<div id="authThumb"><img src="../fluxichild/images/defaultAuth.jpg" /></div>
    				<?php } ?>

    relative image paths might not work properly;
    in this case try for example:
    <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/defaultAuth.jpg" />
    https://codex.www.ads-software.com/Function_Reference/get_stylesheet_directory_uri

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert image from custom field path?’ is closed to new replies.