• Hi all.

    I have created a new instance of one of my blogs as I want to try out a new theme. I have, however, a common directory where I put images, namely the featured images to use in posts.

    Problem is: in my old theme I would control the use of the featured image using a specific “image” custom field within each post. In the new theme, I need to manually define it using a “Featured image” box, while in post edit, on the right sidebar. Once I’m done doing this, the image actually appears here.

    My problem is that I have hundreds of posts and so I’d like to find a way of “telling” my theme from which custom field to fetch the images from. And I want to make use of the hundreds of featured images I already have as well.

    Any hints?

    Many thanks in advance.
    Antonio

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’ll need to edit your theme, specifically the main loop that outputs your posts. You’ll need to change it from using a featured image to getting your image from a custom field. You can find some information on how to do that here.

    Example of the conditional statement for a loop.

    $values = get_post_custom_values("image"); // check before if post has the custom field
    if (isset($values[0])) {
        echo '<a href="'.get_permalink().'" ><img src="'.$values[0].'" alt="'.get_the_title().'" width="150" height="150" /></a>';
    } elseif (has_post_thumbnail()) {
        echo '<a href="'.get_permalink().'" >';
        the_post_thumbnail(array(150,150), array('alt' => get_the_title(), 'title' => get_the_title()));
        echo '</a>';
    }

    Thread Starter saplab

    (@saplab)

    Thanks guys, that has been very helpful.

    Antonio

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using a custom field instead of using "Featured image"’ is closed to new replies.