WordPress.org

Ready to get started?Download WordPress

Forums

Custom Field Issue (4 posts)

  1. Michael Benson
    Member
    Posted 6 years ago #

    Basically I have created a new Custom Field called 'postimage' which stores the URL of an image which I would like to use unique to that post. Stores as a value such as http://localhost.com/images/58.gif for instance.

    I am using the below code and get_post_meta template tag to extract the information necessary but am going wrong somewhere:

    <div class="categoryimage"><a href="<?php the_permalink() ?>" rel="category tag" title="Image of '<?php the_title(); ?>'"><img src="<?php get_post_meta($post->ID, "postimage", true); ?>" alt="Post Image" class="catimage" /></a></div>

    This code is placed within The Loop, yet whenever I try to view a post the following output is produced, as an example:

    <div class="categoryimage"><a href="http://localhost/?p=58" rel="category tag" title="Image of 'Syndicate!'"><img src="" alt="Post Image" class="catimage" /></a></div>

    Where basically the "postimage" custom field of http://localhost.com/images/58.gif is not being found despite the fact it is displayed when I view the Manage Post area.

    Any ideas?

  2. LK
    Member
    Posted 6 years ago #

    add an "echo" before "get_post_meta":

    <div class="categoryimage"><a href="<?php the_permalink() ?>"
    rel="category tag" title="Image of '<?php the_title(); ?>'">
    <img src="<?php ECHO get_post_meta($post->ID, "postimage", true); ?>"
    alt="Post Image" class="catimage" /></a></div>
  3. moshu
    Member
    Posted 6 years ago #

    Isn't there a "post_image" plugin already?
    http://guff.szub.net/2006/02/09/post-image/

  4. Michael Benson
    Member
    Posted 6 years ago #

    Thanks I hadn't noticed this plugin before, however it looks as though this plugin only supports images which are saved as attachments on the server, and what I wanted to do was use images stored externally on websites such as FlickR/Photobucket instead.

    Does anyone know the conditional string I would need to use so that this code would only be displayed when there was infact content in the "postimage" custom field? Since I am using this in the TheLoop.php, and am also using SearchEverything plugn - which means that this post image is trying to be shown for pages/comments which do not have a post image assigned to them.

Topic Closed

This topic has been closed to new replies.

About this Topic