Use The Attachment Image!

Use the Attachment Image! is a WordPress plugin that allows the first attachment image associated with a post to be used in different locations throughout a blog. It’s a perfect compliment for magazine themes.

This plugin can include images of nearly any size, simply by using the included < ?php use_the_attachment_image(); ?> function.

Download this plugin from the WordPress plugin gallery.

See an example of the plugin in use.

Please feel free to ask any questions you may have about the plugin below.

54 Responses to Use The Attachment Image!

  1. Hi!
    I’ve installed this plugin on my site, but when using it on any part of the loop, page stop loading where the image should be printed
    any ideas?
    thanks in advance

  2. Thanks for the note.

    Could you try adding:

    define(‘WP_DEBUG’, true);

    to the top of your wp-config.php file? This will tell you if there are any php errors coming up. Let me know if this produces any errors. If it does not, I would recommend you remove this line when you are done diagnosing.

    I will take a look at the other plugin you mentioned, and see if I can see anything.

    Thanks for helping improve this plugin!

    Tom

    • I am not seeing anything right off hand. Let me know what turning on wp_debug uncovers, because I would like to get this fixed if there are any problems.

      Thanks!

      Tom

    • I’m getting

      Fatal error: Call to undefined function special_get_post_photo() in /var/www/taringacs.net/public_html/wp-content/themes/taringa/index.php on line 32

      Plugin it’s installed!

      • Oh, It looks like I made a mistake in the documentation!

        You want to use use_the_attachment_image() instead of special_get_post_photo()!

        I will make an update to the plugin with the correct variables in the documentation in the next few minutes. Sorry for the problems; thanks for helping diagnose them. Let me know if this doe not fix your problems when you download the new version.

    • Great! Now it’s working fine. Thanks for your work!
      I’ve have a request to made, don’t you wanna try to make this plugin show the first image of the post resized using html if it hasn’t got any attachments?

      Sometimes images are linked but no attached, and your plugins shows nothing actually!

      Thanks!

      • It is probably possible to do so. I have not tried it. I would, however use the function wp_get_attachment_image from core for this, so you are not plugin dependent for this function. Search Google for this function, and it should point you in the right direction.

        Let me know if this is confusing.

  3. Tom,

    I’m trying to get your plugin to add an image from each post to the rss feed. I activated the plugin & added:


    to the functions.php file in my theme. I then resynced the feed at Feedburner and cleared my browser’s cache, but I don’t see any images on the feed. FYI, I’m using the FD Feedburner plugin. Also, the images in my posts were all uploaded using the WP gallery feature & shortcode as opposed to being “inserted”.

    I’d appreciate your help.

  4. Oops. It looks like it’s working now. Feel free to disregard my earlier question. Thanks for the plugin, it solved my problem of trying to add an image to the rss feed.

    • I think that in many cases you need to add a new post before the feed will refresh itself. Perhaps this solved the problem for you. Glad to hear things are working.

      Tom

    • I think something like this would probably work:

      if (wp_get_attachment_image{} == “”) {} else {}

      Put what you want it to do if the image is not present in the else statement.

      Tom

      • Tom, this if (wp_get_attachment_image() == “”) { it’s always true… i can’t get any negative case and i’m sure post got attachment images.

        I’m trying to use something like this

        if (wp_get_attachment_image() == “”) {
        images(’1′, ’200′, ”, ”, true);
        }else {
        use_the_attachment_image(‘full’);
        }

        To use your plugin, and when posts doesn’t have attachments, another plugin pull the first image and it’s resized

        Thanks for your help

    • Actually, you don’t have to specify the image yourself. It automatically selects the first image attached to the post. If you upload images using the image uploader, it automatically picks the one with the highest rank order.

      Let me know if you have any other questions.

      Tom

  5. Dear Tom.
    I think It is very useful to me, so I will use it.
    But I have a question.
    It have many options for the thumbnail size like ‘array(20,20)’.
    I want to decrease 50% for the original image.
    What option I can use.
    Please help.

    • Jake,

      Thanks for the comment. Glad to hear that this is useful to you.

      The function that allows you to make an image a specific sizes does not allow for the use of percentages. I would look at the size of the image you are trying to include, cut the dimensions in half, and use those values in an array.

      For instance if the original image is 200px x 200px, you make the image half of that size, 100px x 100px by using the function: ‘array(20,20)’.

      Happy Easter!

  6. Hi
    I just wan’t to THAAAAAAAANK you for this plugin!
    It’s really saved my time and gived to me a lot of options on my blog so, TAHNK YOU for this great job

  7. Hi Lanre,

    Thanks for the comment! You want to place the function in the PHP template file relating to the place where you want the image to show up.

    Let me know if that does not make sense.

    Thanks!

    Tom

  8. Thanks for the comment, Lanre. Instead of putting the code in each post, you want to put the code in the template file. By adding the code to your template file, the image will be applied to each post automatically on the homepage, with no action necessary on any of the posts.

    You have a WordPress “theme” installed on your server. The theme controls the design of your site. You want to insert the code in the spot you want the thumbnail inside of your template file. To modify the homepage, you will likely want to look in /wp-content/plugins/PLUGIN_NAME/index.php /wp-content or /plugins/PLUGIN_NAME/home.php (could vary based on your theme setup), and add the code in the correct spot there. The code must be inserted within a WordPress loop to work.

    Let me know if you have any questions.

  9. Great plug-in. I use it for my site http://azovsea.in.ua/ . I think i found some bugs. Your plug-in doesn`t display thumbnail for the post if you try to get it from the already used thumbnails (for other posts). So i have to load a new picture to get the correct results.
    Also it will be great if your plug-in can be used with NextGen Gallery for WP. Thanks.

    • Thanks for the note. I am glad the plugin is helpful.

      Unfortunately, images must be attached to a post for them to be able to be used with this plugin. If you uploaded an image with a different post, you are correct, it will not be included even if it was used in another post.

      For my purposes this has worked well, as images do not have to be posted in a post, they simply have to be attached to the post. I am not sure how one would best go about pulling images that are included with the way WordPress code works, but not attached to a page. I suppose one could look for all of the image tags in a post somehow. As you said, the work around is to re-upload images.

      This plugin can probably be used with NextGen Gallery, but would require some integration with NextGen. That isn’t something that I will likely work on in the near future, but it is a good idea.

      Thanks again for using this plugin!

  10. Hi,
    I am using Wp as a CMS and this plug-in does exactly what i need …except… what i would like to do is simply link the ‘thumbnail’ to the larger image so i can use Lightbox. Is this possible?

    I am feeding the content to an external site – so a link to the ‘hidden’ cms blog is a no-no.

    Any help is appreciated.
    many thanks!

    • Hi Dan,

      Thanks for the note. I am working on another website with which I would like to use Lightbox also. It is probably possible, but looks a bit difficult. I will post back here if I come up with a solution.

  11. hi, thank you this is a nice plugin. Thanks for creating it.

    Would it be possible to add a specific class to the image?

    something like
    `
    use_the_attachment_image_nolink(‘size=full&css_class=imageclassname’);
    `

    • Hi Jay,

      Thanks for the comment. This plugin makes use of the WordPress function `wp_get_attachment_image`, which includes the whole image tag. The plugin just tells it which image to grab. Unfortunately, you would have to modify this aspect of the plugin in order to do this. You could write out all of the code for including the image, and include the image with `wp_get_attachment_image_src` instead. It might also be possible to filter `wp_get_attachment_image` to include a CSS class.

      Depending on what you are trying to to, it may be easier to just include a div tag around the image.

      Let me know if you have any other questions.

  12. A couple of people have mentioned that they would be interested in providing some sort of alternative content if there is not an image to be shown. The best way that I can think of to do this would be to place this content (or set a variable equal to something) within the else at the end of each function.

    Let me know if you have any questions about this or anything else.

  13. Hi Tom and thanks for your plugin. First of all, i’m french so i’m sorry for my language. I have a problem with timthumb, a problem of cache memory (i’m not sure it’s the good term).

    Anyway, i seek a alternate soluce, and i find your plugin. I have test your plugin in my local server, i use in loop … but the image have for size 50px / 50px … i don’t know why :/

    Other problem, this plugin take the first image of my post, but when i change my image, the thumbnail shows the same image .. :(

    If you can respond it’s very nice !
    Thanks a lot
    Amity.

  14. Oh i see that my post is cut. When i try to use your function array (95,50) cause i want my image has for size 95px / 50px but my image is 50/50.

    Re-Thanks a lot
    Amity

    • Hi Amity, Thanks for the note. Glad to hear you are using my plugin.

      Check your function with the documentation one more time — It’s important that the parenthesis are in the right places. The function should look something like this: `use_the_attachment_image(array(95,50));`

      Also, it’s important to note that my plugin simply shows an image as a different size, but it does not actually make a smaller copy of the image on the server in the way Timthumb does. For this reason, it may make sense to talk with your host and try to get the memory issues resolved if Timthumb was working well with your site. Alternatively, SLIR works similarly to Timthumb. You might want to check it out if you can’t get Timthumb to work and need its functionality.

      Let me know if you have any additional questions.

  15. Ciao , i’m trayng to use the plugin in feed but no image show!
    looking in the source code of the page i found instead o the image :
    i put the code in function.php All my post have 3 or 4 attach post image.
    thanks

    • Hi Max,

      Sorry this plugin isn’t working for you. Have you tried simply activating the plugin on your site, instead of placing the code in functions.php? Also, make sure that you are calling this function within a WordPress loop.

  16. I’m sorry, I cant seem to get this to work. I have an image attached to a post entitled Product 3, and when I insert inbetween my div to hold an image, I get a blank.

    Here’s my code by the way:

    <div class="post" id="post-”>

    Your help is greatly appreciated :)

    Derek

  17. Hello,
    I am trying to have Thumbnail image together in my post. If you check my web – for example RECENT POSTS – text from RSS if fine but Thumbnail image must be always added manually – even if is attached in RSS. Could you help me with this – how to added Thumbnail image to my post?

    Thank you and Have a nice day from Czech Republic

    • Hi Petr,

      Thanks for the note. It’s great to see you’re using this plugin. In order to include an image in the RSS feed automatically, you need to add some code to your theme’s functions.php file. See the bottom of this installation instruction page for more information. It looks like you currently have at least two images being displayed for each item in your RSS feed. I’m not sure if these were added by this or another script, or if they were added manually. Let me know if you have any other questions or need more help.

      Thanks, and have a great day!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>