• Resolved kbkisan

    (@kbkisan)


    Hi there,

    I’m new to this whole wordpress thing, but I’m really impressed so far. The thing is that I’m using the template Autofocus and when creating a post that contains an image the template automatically creates a custom field to display that image.

    What I am trying to do is add my own custom field, to have the option to have a different image on the frontpage than in the post itself, so what I want to do is to use an if statement to check if my custom field exist and use that as the image, and if it doesn’t exist use the one created by Autofocus.

    I’m not sure if I am making my self clear but I am going to post the code I have so far

    I have created this code here that displays the image from my custom field called front_image

    <span class="attach-post-image" style="height:250px; display:block; background:url('<?php if(get_post_meta($post->ID, 'front_image', true)): ?><?php echo get_post_meta($post->ID, 'front_image', true); ?><?php endif; ?>') center center repeat">&nbsp;</span>

    What this does is to check if my custom field exists, and if it exists it adds it as a front page image.

    Now the original code from Autofocus is this one.

    <span class="attach-post-image" style="height:250px; display:block; background:url('<?php the_post_image_url('large'); ?>') center center repeat">&nbsp;</span>

    This code takes the custom field created by Autofocus and puts it as a front page image.

    I am looking for a way to mix these two together so I can have wordpress first check if there is something in my custom field, and if not then use the Autofocus custom field.

    Any help is greatly appreciated
    Thanks in advance,
    Fannar

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kbkisan

    (@kbkisan)

    Is there anyone that could help me out on this one ?

    Thread Starter kbkisan

    (@kbkisan)

    Well when in need one often stumbles upon the solution.

    This is what I did to achieve what I wanted.

    <span class="attach-post-image" style="height:250px; display:block; background:url('<?php
    if (get_post_meta($post->ID, 'front_image', true))
    	echo get_post_meta($post->ID, 'front_image', true);
    else {
     	the_post_image_url('large'); ?>
    <?php
     }
    ?>') center center repeat">&nbsp;
    </span>

    nice work, I’ll be trying this myself on my version!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If statement to display images’ is closed to new replies.