WP plugin: Post Image
- plugin:
- Post Image
- version:
- R1.1.1
- download:
- post-image.zip
- source:
- post-image.php
Post Image is a WordPress 2 plugin that displays an image attachment for a post through the plugin’s post_image() (or szub_post_image()) template tag. It’s useful if you want to provide a unique “post image” to each post without having to manage the image references and tags within each post.
If you’re not too sure why someone might want this or what uses you could put it to, this WP support forums’ thread may help explain things further. A few points of interest:
- Displays the first image attached to the post, or alternatively an image using either the postname (i.e. post slug) or post ID of that post for its filename (i.e. title-of-post.jpg).
- Uses either the full image or thumbnail (see info on ‘use_thumb’ parameter below).
- You can specify which image attachment to use by inserting the text ‘
post-image‘ (or what is set for the ‘customkey’ parameter) somewhere in the image’s title field. - You can define a default image (through the ‘default_image’ parameter) for posts without an image attachment.
To install Post Image, download the zip file, extract post-image.php from it, upload this file to your wp-content/plugins directory in your WordPress installation, and activate Post Image under Plugins. To use, the template tag <?php post_image(); ?> (or <?php szub_post_image(); ?>) must be placed somewhere in The Loop portion of your theme’s templates.
Usage:
<?php post_image('default_image', use_thumb, img_tag, 'css_class', 'customkey', display); ?>
~or~
<?php szub_post_image('args'); ?>
Parameters*:
- default_image
- (string) URL to an image displayed when no image attachment exists for a post. There is no default.
- use_thumb
- (boolean) Display the thumbnail rather than the uploaded image attachment itself. Set to
TRUE(1) to use thumbnail image. Default isFALSE(0). - img_tag
- (boolean) Display in an <img> (image) tag. The plugin will automatically populate title (with attachment title), alt (same as title), and width and height attributes for image. Set to
FALSE(0) to display the url *raw*. Default isTRUE(1) - css_class
- (string) CSS class name provided to the <img> tag. Use this for styling your image(s). Default is
'post-image'. - customkey
- (string) Image “attachment” custom field key. Use this—with the url to an image as the custom field’s value—to override the image attachment and/or default image for individual posts. Default is ‘post-image’.
- display
- (boolean) Whether to display the image (or URL) or return it for use in other code. Set it to
FALSE(0) to return only. Default isTRUE(1).
* For boolean parameters, use only the value in parentheses (1 or 0) with szub_post_image().
Examples:
<?php post_image(); ?>
Defaults: No default image for posts without an image attachment; display full image attachments (not thumbnails); display in an <img> tag; use ‘post-images’ for the css class.
<?php post_image('/blog/wp-content/images/post.jpg', true); ?>
Use ‘/blog/wp-content/images/post.jpg’ as the default image, display thumbnails for image attachments; display in an <img> tag; use ‘post-images’ for the css class.
<a href="<?php the_permalink(); ?>"><img src="<?php post_image('/images/posticon.png', false, false); ?>" width="32" height="32" /></a>
Displays image attachment URL in an <img> tag (within a link <a> element), which is the permalink to the post. Parameters are: use ‘/images/posticon.png’ as the default image; display full image attachments (not thumbnails); display the URL in raw form (no tag).
<?php $thumb = szub_post_image('use_thumb=1&display=0'); ?>
<?php if($thumb) : ?>
<p><a href="<?php the_permalink(); ?>"><?php echo $thumb; ?></a></p>
<?php endif; : ?>
Uses szub_post_image() to assign thumbnail of the image attachment to $thumb (‘display=0′ turns off echo), and if it exists makes it a permalink to the post.
post-image‘ (or rather, whatever is set for the ‘customkey’ parameter) somewhere in the title field for the image upload; this text is parsed from the title attribute. Also dealt with a language localization issue for the ‘thumbnail’ filename. And implemented pseudo-caching on multi-post queries (just one query!), taking care of one of two major annoyances I’ve had with the plugin. Still extant is invalid image urls if/when a blog is moved.szub_post_image()); post image attachment and/or ‘default_image’ can now be overridden for individual posts through a custom field (default ‘customkey’ is post-image); when ‘img_tag’ is set to true (1) and ‘display’ false (0), Post Image now returns complete <img> element (previously it returned only the image’s url). Tentative support for WordPress 2.1 has also been shoehorned in.
Author: Kaf Oseo
Categories: WordPress
Comments: (212) · Leave a comment · Comments RSS2
The link to the “this WP support forums’ thread” is linking back to this post :)
Fixed. Sometimes I drop an empty <a> or two in a post, but forget to go back and fill them with something…
Kaf,
You have any screen grabs or live demo of this? I’m not totally sure I follow what this is all about…I are a moose, after all! :)
Oh, wait…never mind, I get it now! LMAO!
I have this up and running and it works great. Was searching for something exactly like this for a while.
One question: When creating a new post, in the WP admin image area, how do I select an already-uploaded image to use?
I tried clicking “send to editor”, but this obviously creates the image twice in the post.
Will, sorry but at this time there’s no way to do that. The plugin gets its cue in regards to image attachments from WordPress, and WP offers no functionality for attaching an image (or any other file) to more than one post. However when I update the plugin I’ll look at providing a method for *assigning* a different image through post meta (custom fields).
sounds great kaf!
can you shoot me an email whenever you do update this plugin?
thanks!
Thanks! I am very appreciative for what you have done already, so don’t bend yourself over backwards for this.
Hey there. I also have this up and running and it’s great. I totally agree with Will that it would be excellent to choose from an already uploaded image. If that functionality were there, this would make it even cooler than it already is. Thanks for taking the time to work on this.
I agreed as well. Which is why you should take a look at the update (R1 – March 17). It provides one the opportunity to specify another image (or rather, it’s url) through a custom field. A simple fix, but I happen to like those kinds.
I’ve been looking for something like this, Are the images “linkable” ?
Examples:
Post 1 has image A, image A can link to X. X = google.com
Post 2 has image B, image B can link to X X = digg.com
Post 3 has image A, image A can link to X X = guff.szub.net
The images link to where pointed to on a post by post basis, possibly having a default link if not specified in the post.
Does it do this? If not what needs to be modified? Thank you so much.
Would this allow me to upload more than 1 image from my computer at a time?
Looks like a wonderful plugin! :)
Does it also resize the original-size images to fit a theme layout and/or download-size considerations? It would be great to have at least 3 sizes: thumbnail, resized-large, and original image.
Thanks!
hello. i’m trying to do something a little bit different with the plugin. i’ve added a custom field called author_photo that contains the url to an image. i’m trying to set the url in the post_image call based on that custom field. what i’ve written so far is this:
post_image(get_post_meta($post->ID, 'author_photo', true),false);the above code isn’t working and i know that i’m doing something wrong but i just can’t figure it out. thank you for the help and for writing the plugin.
Hi
Thanks for the plugin it works, however the default image setting does not work in my environment. It simply doesnt display anything. i can’t show because it is on an intranet blog :-(
But I use the normal code:
Any help is appreciated ;-)
Hendrik
Wonderful plugin. I’m currently using it to display thumbnails from my portfolio page on my home page.. sorta like a latest entries thing, only with thumbnails.
One question. Is it possible to link to more than image per post with this plugin? So that I can use image1 for the home page, image2 for the porfolio main page, and image3 for the actual portfolio entry. I’m currently getting around this by adding an image to the excerpt field of the post and hiding one or the other through CSS depending on the page that is being viewed. Kind of a messy solution, but it’s the only alternative right now.
Can linking to more than one image attached to a post be done?
Again, great work with the plugin.
Hi.
Can you please help a newbie?
I’ve installed the plugin as instructed.
The post_image() returns nothing.
How do I actualy choose the image for the post? I don’t see any field for that in the admin system…
Thanks.
another question –
i am trying to display the post image as a thumbnail with the title of the post, in the “recent posts” in the sidebar. is it possible? and if so, how – I’ve tried to put post_image in the recent posts php file beside the post title but it doesn’t work
thanks :)
Hi all…
I am trying to use “Post Image” on WordPress 2.0.2 is it compatable?
I placed the needed text to my themes template loop and placed the post-image.php file in my plugins folder. After I activate the plugin i get the error message below. I am using the default theme and have
The ERROR message:
Parse error: syntax error, unexpected T_VARIABLE in /home/.chani/me/me.com/blog/wp-content/plugins/post-image.php on line 92
Can anyone help?
Thanks for your time.
Red
ok
I got rid of the error message by changing “use_thumb=true” and , “img_tag=false”
But I still don’t see how a user can upload a pic? Yes… I am new and need help!
Thanks
Red
Hi Kaf ! great work you did here, but is there something i am missing ? :
when using the plugin with use_thumb=false, everthing is okay, but when use_thumb=true, “array” is echoed instead of the thumb… ;(
any idea ?
thanks anyway for the cool plugin !
Hi, I’m having trouble figuring out how to use the plugin.
I have assinged a class to an image in a post, but I can’t figure out how I’m supposed to write the php code for the loop so it uses the class.
I’ve gone through the instructions on the page a few times, but it just escapes me.
Any help would be appreciated.
There seems to be a conflict between the post-image plugin and Lightbox JS version 2.0 ie: when this plugin is activated it stops the Lightbox effects across the whole site, regardless of whether the page even calls the post_image function.
Anyone got any ideas on how to fix this?
In regards to the above problem …. I found that there was an extra space at the end of my post-image file (ie: after ?> ), somehow this was messing with the Lightbox plugin. Delete the space and problem solved!
Hi Kaf,
I’ve WP 2.0.2 italian localization and have installed your plugin without errors.
I placed the function call in The Loop, but the function doesn’t return nothing. I tried with the examples of this post (with my URL paths to images) but without success.
In database i have some “attachments”, so if I try to run your query (with static parameters) directly in MySQL it works fine.
Have you some idea?
Thx a lot
Hi Kaf,
first of all let me say thanks a lot for this wonderful plugin!
I have one problem with it, though: when I try to override the attachment with the custom field ‘post-image’, all uploaded images disappear and unfortunately the one specified in the custom field doesn’t show up either. I’ve tried various paths, but even with the complete path it wouldn’t work. When I delete the custom field, everything is fine again. Am I doing something wrong or did I mis-read your instructions? I’m using ” in the loop, no modifications at all.
I’d appreciate it very much if you have any input on this. Thanks!
Is it possible to use post_image() in conjunction with get_a_post(‘GETSTICKY’) ??
On the front page of my site, I have the five most recent posts plus a sticky post that will sit at the top of the page. This hero post should also contain an image, which I want to display on the front page.
post_image() works…uhh, most of the time in my site. But it won’t display the image for the sticky post – I guess, because it’s not within The Loop. Is there any way to get this to work, or should I just take a different approach?
All help is welcome!
can this plugin be modified to allow registered users of my blog to attach an image along with their post?…if not, does anyone know of one?
Hello Kaf,
I put a post on the wordpress forums about trying to get an image associated to a post or Page to appear in a navigation list that is created with the wp_list_pages function.
Do you thinkg this plugin could do the trick? If so, how?
Otherwise, thank you for doing great work. I do like your work.
Hello,
I was very excited to see that the Post Image plugin handles most of what i was looking for, except handle multiple images. I am going over the php to see how to modify it, but wondered if someone has done this already.
Secondly, I can not get a default image to display. this is the function call
post_image(‘http://www.site.com/images/image.jpg’);
the actual image link is good, but this never brings up a default image.
Thanks So Much!
chuck
Another great work from Kaf!!
But i have the same problem of jide: when i call post_image function with thumb set true, i get only “array”…
Any ideas?
The plugin sounds great, I’m trying to make this plugin work but I think I’m missing a step or two. I installed it as intructed above, activated it and added the line of code to the template file, but then I’m not sure how do I implement it.
I have php post_image(); in the loop, but what do I do after everything is in its place? When I am writing a post, how do I actually tell wordpress to use this or that image, so it displays where i putted in the code?
I have tried a bunch of things and nothing has worked so far.
Any help is appreciated. thanks!
Hi Kaf -
Heard a lot of good things about your Post Image plugin; good work! I wanted to know if it’s possible to use or manage captions… ? I’m currently using a DIV and a CSS class to achieve this within the post content.
Thanks!
First of all, thnks for the plugin! Now i have to learn how it works, because i only know the basic stuff. I placed that thingy in the loop file. (just somewere is that ok?) And i’ve tried some things with the ‘custom fields’ but that didn’t work.. And i’ve read something about naming it the same as your post but that didn’t work either. Can someone say what i need to do. I don’t understand that usage part.. :( (for example my post name is ?p=13 or is that wrong already?)
This is very cool, I’m implementing it now. In the past I’ve put a caption underneath my image to explain it and give credit. I can put this into the title when I use WordPress’ upload box, but is there anyway to access it again? Is there some way I can have it display the alt text for example? So I would do:
<div class="article_images"><?php post_image(); ?><br /><?php post_image('caption'); ?></div>That would display the image and then the caption underneath. All created dynamically.
Does anyone know how to access this functionality from within the RSS feed? I’d like the images to show up there as well to spruce up my feed. I’ve tried just using the post_image() function, but it doesn’t work.
I’m having issues trying to make it work in the RSS as well. Any help is appreciated. thanks
Thank’s for the great plugin. It was just what I needed for at site I was making! Keep up the good work!
Any ideas/suggestions on where to start to allow the plugin to display multiple images if they exist for a single post?
Hello Kaf, thanks for the plug-in. I’m getting the same error as jide and Lizhard, however, and it doesn’t seem like it’s been addressed. I keep getting the word “array” and no images… any thoughts on this? Thanks in advance!
To Naomi
(or to all who are getting the word “array ” instead of the image linked to your post.)
Your problem can be due to an entry in the table post_meta linked to the post_id from an other plugin for example.
Or if you witched language, the plugin may not find the url of the thumbnail.
Edit post-image.php change :
$img_url = preg_replace(“/.$ext$/”, “.thumbnail.$ext”, $img_url);
to
$img_url = preg_replace(“/.$ext$/”, __(‘.thumbnail’).”.”.$ext, $img_url);
Voila ! Hope this will help.
Laurent A.
http://www.laurent-aronica.lu
I cannot set chmod to 777 for image upload below Write Post window. Is there a way to use this plugin with the image icon in the Write Post window? I’d really love to be able to use this plugin.
I am trying to use this plugin and so far it is showing images but it is showing the same image for all the posts in a category.
I have attached individual images for each post, but it always returns the first post’s image and displays that.
Any ideas?
No problem, I just was being stupid and I had the function outside of the Loop. So I just set a variable and put in the image where I needed it. Great function, just what I needed for my project.
I’m getting this error, any clues?
Warning: Cannot modify header information – headers already sent by (output started at /home/fourstar/public_html/touchjay-com/wp-content/plugins/post-image.php:103) in /home/fourstar/public_html/touchjay-com/wp-admin/plugins.php on line 22
Ya, I tried that
preg_replacechange but I’m still gettingArray. Anyone find any success??hi! i like your plug-in very much. but i have a problem with it after porting my development version from my local (MySQL: 5.0.18 / PHP: 5.1.1) machine to my webserver (MySQL: 4.0.26-Max-log /PHP: 4.4.1). now there’s only a “array” string where the images schould appear. Is it because the different php/mysql versions. is there a possibility to solve this problem by changing something in the script? i would appreciate any help very very much.
greetings, Bernd.
(the problem-child: http://www.destroy.wennsrockt.de > http://destroy.wennsrockt.de/index.php/category/sendungen/)
I solve the problem with “ARRAY” when you want to show thumbnails.
This plugin make thumbnail from uploading picture and add “.humbnail” in the end of the file name of the picture… If your site is non english (like mine), you should check the upload directory for thumbnails name. In different language there is a different translation of “thumbnail”.
And the line :
$img_url = preg_replace(“/.$ext$/”, “.thumbnail.$ext”, $img_url);
should look like :
$img_url = preg_replace(“/.$ext$/”, “.THUMBNAIL-IN-YOUR-LANGUAGE.$ext”, $img_url);
I hope it’s clear :)
Sorry for my bad english.
Mike, thank you vermy much for your reply. I checked my thumbnail-files. they in deed are called *.thumbnail.* ..thus unfortunately this seems to be not the solution for my problem. :(
Furthermore “array” appears nevertheless I us “use_thumb=1″ or “use_thumb=0″ (in $thumb = szub_post_image(‘&use_thumb=1&display=0&css_class=teasersmall’);)… hmm..strange
Very strange… In directory /wp-content/uploads/(year)/(month)/ I have orginal picture size name, for example let’s call it “beauty-pic.jpg” and the thumbnail from this file has name “nice-pic.miniatura.jpg”
“miniatura” means thumbnail in polish :)
I’m using wordpress 2.0.4 with polish lang utf-8
Here is my test site : wordpress test
hmm..strange. I used var_dump($thumb) to take a look inside the array. On my local testserver (where the image is perfectly displayed) it says “string(173)” whereas on my webspace (www.destroy.wennsrockt.de) it says “array(2) { [0]=> string(13) “queenadreena1″ [1]=> string(3) “jpg” } Array” an no image is displayed.
What does this mean?
Multi attached image …
I have in each post more than 1 image, but its showing just 1 of them, I think you have to use arrays to view them all, any idea plz ?!
It has to be placed under the loop?
If anyone can help me figure out a way to either select the css class while posting or have it selected automatically based on the image width I would greatly appreciate it.
For example:
if img width is less than "300px" then {class="small"}else if img width is greater than "500px" then {class="large"}
else {class="medium"}
end;
I don’t really know php all that well, but would have no problem editing the file if told what to add. Huge thanks in advance if anyone can help with this!
The Array problem.
This is because of this line in the code:
$img_path = ABSPATH . str_replace(get_settings(‘siteurl’), ”, $img_url);
It replaces the occurence of the site url in the GUID in the database for each post with the path to the image.
If you built your site somewhere else – like on a development server or another web address, then the OLD web address will still be in the database. A quick fix for this would to be to replace it with these lines:
$img_path = str_replace(get_settings(‘siteurl’), ”, $img_url);
$img_path = str_replace(“http://www.myoldwebsiteaddress.com/”, ”, $img_path);
$img_path = ABSPATH .$img_path;
Hope that helps someone. WARNING. This is a quick and dirty hack – I’m sure the author will fix this properly.
Stef
A nice plugin :) There is a small problem with it in my case though – I use ecto desktop application in order to publish posts to WordPress and when I attach an image to the post, it somehow doesn’t get really “attached” to the post, but rather just uploaded to server and hard-linked from the post (so there is no connection between the image and the post in the database, I guess not even an entry). All this is done using xmlrpc protocol, so I think that’s the way it works and not a flaw in the software.
So, the idea is to display the first attached image for the post if it exists, but also add user an option to use the first image from the post content in case no attached images are found. And only if there are null results in both cases display the default image if it is set by user.
How about that?
First of all, I would like to thank the writer of post-image plug in for the time he spent on this script and sharing with us. I was not able to use it so far, But I am sure many do. I was hoping that the writer or anyone with a knowledge of it can assist me and answer a few questions that I have as I only have basic knowledge of scripting.
Our website is a sporting website and the url of front page is:
http://www.iranfootballonline.com
As you can see, we have word press showing up in the body of our front page, including the images. We use FCKeditor to post images.
What I want to do is to make the images appear as thumbnails in the latest news section with full image appearing when one clicks on a title to read the whole news. Something like the following:
http://www.iranfootballonline.com/revised
Please notice that I want the images to appear where there is an X as thumbnails of around 120*100 pixels. (Please disregard the text malalignment.)
Now, for our current front page we use the following command to call the post content and the images:
$textfive = substr((strip_tags($rowfive['post_content'],’,')),0,380) ;
echo ” “.$textfive.”… more …” ;
This is a strip tag. the problem is, I cant separate the images from the text. they go together.
Now to my question. Does post-image do what I aimed to do as explained above?
If yes, I have went through the instructions. Uploaded the post image php under appropriate place and it shows up fine under plug ins and I can activate it. My problem starts there. There is a talk about “The Loop”. I read the article about it, but still I have no clue where I can find it. When that issue is solved, where and what do I put the command that makes thumbnails of those images corresponding to each post?
I had a technical person who did stuff like that for me. I learned quite abit of scripting in the past few months thanks to people like you. But I can neither get hold of my technical person, nor my knowledge has become sufficient enough to answer the above questions.
I would really really appreciate any help that I can get in this matter.Thank you so very much.
Sol
We are using wordpress version 2 and the template we use is connections 1.0. I dont know if with our setup, template matters or not at all.
Great plugin, thanks!
Since switching to Live Writer though I had the same problem as a previous commenter mentioned with Ecto/Metaweblog. Posting via this method only allows you to insert images, not attach them in the same manner that the WordPress GUI allows.
To fix this I’ve changed the plugin so if a post has an image inserted it will use that in preference to any attached image. Some people might prefer it the other way, but that works better for me since the majority of my posting is now done via WLW :)
If anyone needs similar behaviour at the top of the post_image function add the following underneath the line of global variables;
if (preg_match(“/src=\”([^']*?)\”/”, $post->post_content, $matches)) {
$img_url = urldecode($matches[1]);
$img_title = apply_filters(‘the_title’, $post->post_title);
}
else {
And then add a trailing } above the line that starts ‘if(!$img_url) {‘
A.
// existing code
if(!$img_url) {
I have tried adding the code to the loop, and nothing happens. the image remains where it is in the post. Maybe I am doing something wrong…. would apprecaite some help….
why don’t you have an optional argument with the postID? If one would like to use the image outside the loop and provides a post id for which he wants to show the image to be able to use your plug-in.
i am making on my front-page some querries searching for different things and i’d like for example to display the image and the title of the post.
it’s just a possibility so think about it ;)
Hey Kaf,
Amazingly useful plugin! Just one question. I installed the plugin and it worked great in the loop on my archives.php , then I used a custom query to get my posts by rating and now your plugin doesnt work in the loop. The ratings plugin still works either way. Any ideas? Thanks for your hard work!
I’m still unclear as to whether I can access multiple images uploaded to a post or if I can only access the first one. I need to be able to access multiple sizes/crops and use them in different places. Is that possible? thanks
did you by any chance test this Post-Image-plugin with wpmu 1.0? (it works fine with wp 2.0.X.)
please be kind and run the Post-Image-plugin with wpmu and tell me if you encounter any problems.
if everything is allright with it I will have to look into my configuration.
thanks,
-Ray
Awesome plugin! Have any of you used this plugin on the sidebar, with say, random posts or most recent posts? How does it work? I’ve got it working in the loop but can’t figure out how to make it display on the sides?
TIA
Hi – I, too, would appreciate any advice on using this [great, fantastic, meraviglioso] plug-in on the side bar. Thanks!
Kaf,
Wanted to check something with you before I start looking under the hood. I’m giving the plugin a look and it works as advertised. One question, I’m using the custom key option with post-image:
szub_post_image('&img_tag=1&display=1')What I was wondering, and maybe I’m overlooking it, but if the post-image custom key is not assigned to a particular post — I’d like it default back and show the post title. Is that an option I’ve missed in my reading?
This plugin is causing my site to load super slow… any suggestions on how to fix this?
Is causing the query time to take literally over 100 times longer.
What a great plugin!
The Array problem… I am also developing on a development server as well, if you are doing this, to follow stef’s hack, you may need to dive into the mysql database, in the wp_posts table, check the GUID row, it will reference the file directly.
Kaf,
Messed around and got my desired result.
Tweaked lines:
$img_path = ABSPATH . str_replace(get_settings('siteurl') . '/', '', $img_url);
if(file_exists($img_path)) {
if($img_tag && $meta_value != '') {
$imagesize = @getimagesize($img_url);
$image = '';
} else {
$image = $post->post_title;
}
}
This code change should now display the post title, when using
szub_post_image('&img_tag=1&display=1'), in the event that $meta_value is empty…also included is a path fix issue for $img_path…was seeing /my/path/here//image/blah.gif — double slashes…Hi kaf
your plugin work geat for me . wel i have only one problem, i dont get image ALT attribute for thumb nail
curretly i am using this
To post all images from the upload area of the post, add this under function post_image():
//call it like this
//works for me, any input on this would be grateful
function post_image_multiple($default_image=”, $use_thumb=false, $img_tag=true, $css_class=’post-image’, $customkey=’post-image’, $display=true) {
if(!in_the_loop())
return;
global $post, $wp_version, $wpdb;
$id = (int) $post->ID;
$name = $post->post_name;
if($wp_version post_title);
} else {
$attachments = @$wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_parent = ‘$id’ AND $record = ‘attachment’ AND post_mime_type LIKE ‘%image%’ ORDER BY post_date ASC”);
if($attachments) {
foreach($attachments as $attachment) {
$img_url = $attachment->guid;
$img_title = apply_filters(‘the_title’, $attachment->post_title);
$imginfo = pathinfo($attachment->guid);
$ext = $imginfo['extension'];
$image = explode(‘.’, basename($attachment->guid));
if($id == $image[0] || $name == $image[0]) {
$img_url = $attachment->guid;
$img_title = apply_filters(‘the_title’, $attachment->post_title);
}
if($use_thumb)
$img_url = preg_replace(“/.$ext$/”, “.thumbnail.$ext”, $img_url);
if(!$img_url) {
if(!$default_image)
return;
$img_url = $default_image;
$img_title = apply_filters(‘the_title’, $post->post_title);
}
$img_path = ABSPATH . str_replace(get_settings(‘siteurl’), ”, $img_url);
if(file_exists($img_path)) {
if($img_tag) {
$imagesize = @getimagesize($img_url);
$image = ”;
} else {
$image = $img_url;
}
}
if($display)
echo $image;
else
return $image;
}
}
}
}
I can’t seem to find the download link for the plugin?
Sorry, Ted. Was a problem with my single post theme template not liking things in (the new) WordPress 2.1. All better now.
I’m also having a very slow load while using the plugin.
With this template style i get 53.736 secs with 72 database queries load time (displaying 56 articles)
">COuldn’t paste code, but all i call is the title, the post_image and the permalink…
I updated to the latest versions, and i get this:
42.108 secs with 15 database queries
less queries, still slow load…
in wp 2.1, doesnt work fully, default_image doesnt appear
Hi
oke great plugin. Thank you very very much, but…. ;-)
I can’t get it to work with pages that are displaying a category. My permalinks structure is: /%category%/%postname%/
when I go to the following url: http://www.blog.com/%category%/ post-image plugin only displays the default image
I used the following code to make a page display a category and make pagination work, if I used just category.php pagination doesn’t work because I wan’t to display only one category, the code:
oke here's a link to the code I used Making your blog appear in a non-root folder
so why isn’t your great plugin working?
thnx
code disappeared:
euh?
Okay, this is driving me nuts. I’m trying to implement this plugin on my site but it won’t work properly.
I was previously using Constantinos’ Image2Post, but it’s so clunky to use and whenever we update our articles we need to re-link the image to the post, causing much frustration when we’re doing lots of minor alterations. I initially decided to try out your Post Image plugin so I could properly show images inside post excerpts on the front page, since WordPress doesn’t allow that by default. At the same time I figured that the ability to easily show pictures by naming them with the post ID was a great timesaver for us (as opposed to our Image2Post problems).
But now I can’t seem to get this to work. I’ve attached images to the post (naming them 566.jpg or title-of-post-whatever.jpg), but they still won’t appear inside the article. Now, I’m not really good with WordPress, I suck at coding for it, but this whole “The Loop” thing is really confusing. If I understand this right, I just have to add this to the index.php (somewhere inside The Loop):
And then it should work by default… so that any images I’ve attached to a particular post should be displayed. Right? Well, I can’t get it to work! :(
Do I need to add the post_image code to many different php templates or is it enough to insert it into index.php? What am I doing wrong?
Me again. I added the post_image code to single.php and it works there, images can be thumbnailed or whatnot… this will make posting images easier once I’ve tweaked it a bit. However, I have another problem: Whenever I view an article that doesn’t have any image attached, I get the following error instead of the transparent 1×1 GIF I picked as a default image to show:
Warning: Invalid argument supplied for foreach() in /usr/home/gameover_is/www/wp-content/plugins/post-image.php on line 82
What could I possibly be doing wrong? My post_image line for single.php is as follows:
?php post_image(‘/www/wp-images/media/the_vastness_of_space_compels_you.gif’, true); ?
@Robert
I get the same error, but only for one category. Very weird.
I got rid of the line 82 error, and didn’t seem to break anything, by doing the following:
Find line 85 in post-image.php, and insert this if statement:
if ($post_image_attachments) {right before this foreach statement:
foreach( $post_image_attachments as $attachment ) {and add a closing bracket around line 108
}before this line:
if( $use_thumb && ($img_url != $default_image) )If you can’t get images to display, try setting use_thumb to false.
There’s a bug when displaying either really small files or gifs (I’m not sure which), which do not generate thumbnails when uploaded. If use_thumb is set to true, the image will not display if no thumbnail is found, even if the non-thumbnail version exists. This drove me crazy until I figured it out. I’m using WP version 2.0.4 I believe.
Hi everyone!
Basically, i need exactly what’s on this site:
http://www.videofanzine.de/
I’ve been playing with this plugin for hours and came up with nothing. I also found this topic http://wordpress.org/support/topic/65180 but again I couldn’t make it to work. Can someone help me?
The plugin isn’t working for WordPress 2.1 and I’ve used this plugin for a long time… I’m sort of disappointed because it affects a lot of my entries. Any fix?
Okay, that was weird. I uploaded two pictures and that’s when Post Image didn’t work. Has it always been like that? I just deleted both image files, reuploaded the one I wanted to show up and then manually uploaded the other to use within the post.
nope … not working on a conventional 2.0.4 installation; had the array problem and did not want to hack, new release r1.1.1. does not fix it :-(
solution: I’ll stick with the regular tags :-D
Sweet plugin!
This allows users of wordpress to just upload a picture, and they won’t have to think about inline positioning/order.
You provide a lot of good plugins guff.szub ;)
(btw, your input order in commentform is broken/missing)
Eric, i had the same problem as Robert and your fix worked fine!
I to am running into issues in 2.1. I had the pluggin working fine in 2.05. After upgrading I was only able to display the default image. Not sure whats going on, but I may have to downgrade to version 2.05.
The plugin wasn’t working with my 2.1 WordPress installation, but I just discovered that the problem is with my version of MySQL (5.0.18), which has a bug that causes the field “post_parent” in the posts table not be updated properly when a image is uploaded. For example, if I upload an image to the post with ID 19, the row that represents the image in the database should have the “post_parent” field equals to 19, but in my database it’s been recorded something like “-123881723″, so I have to update it by myself in order to the image display properly.
I installed this plugin and it is great. I wanted to align the pics to the right and I managed to do that with a div … can anyone tell me how to wrap text around it now? Thanks
I get the following error message when I activate the plug-in:
Warning: Cannot modify header information – headers already sent by (output started at /home/adampsau/public_html/tadias/wp-content/plugins/post_image.php:127) in /home/adampsau/public_html/tadias/wp-includes/pluggable.php on line 275
Great plugin! If you’ve got the time, it would be awesome if it went a step further and would fade between multiple images. I tried to hack it myself but gave up. I tried using the “Ultimate Fade-in slideshow” on Dynamic Drive but I’m bad with other people’s scripts =P
PS. Your comments form AND your “Szub sections” menu both use the same tabindex values, so when I go to type a comment and hit tab, it moves me to the top menu and I have to scroll down again ;-)
I’ve the same problem of Vinicious, the post_parent id usually is set to “-123881723″…
Is this a Wp bug or a post-image bug? Anyone know why it’ happen?
I ran into some problems when using this plugin with multiple loops on the same page (displaying my portfolio by category). The main problem is that it looks at the global $posts variable which doesn’t seem to get updated properly when a template uses query_posts() to start a new query. This can be fixed by pulling from $wp_query->posts. Another problem is that the caching of results in $post_image_attachments doesn’t get reset when a new query is run. Anyway, changing the first few lines of post_image like this will fix both issues.
global $post, $wp_version, $wpdb, $wp_query;
global $post_image_attachments;
if($wp_query->posts!=$posts)
$post_image_attachments='';
$posts = $wp_query->posts;
After a couple of hours/days I am still trying to get the plugin to postimages into my sidebar at http://www.digitalencore.co.uk. It obviously cant seem to link to the images from the recent posts in that category. Is there anything i need to do when upload the image to the post – so that postimage can recongnize it.
I am a bit of a wordprss / php novice and have cannabilised offer people codes which i have found on the internet. If anyone has any suggestions that woul dbe great.. cheers Kaf for the plugin – it looks like the perfect plugin in for me – if i can get it to work
Wanted to update the plugin … but it crashes. So I went back with the old version, which works fine. It missed a lot of “new” samples codes …
it seems not to be compatible with WP 2.1.x and according to Vinicius comment, it might be due to table changes in WP 2.1.x
I have the plugin working nicely, however, I just upgraded to 2.12 and, trying to use the new built-in static front page feature, for which I am using the Post Image plugin to display thumbnails… however, when the page is displayed like this, as a “Page” it generates a blank src url for the image.
Hi there!
I’m a convinced user of your plugin, too.
It came in very handy and suited all my needs.
Btw I found a bug:
You use strpos() to determine, if the ‘customkey’ is present in the title.
While modifying the code to use the description field as ‘customkey’-field
i noticed that you check if the result from strpos == true (line 94);
It should be altered to strpos !== false (strict), because
if the ‘customkey’ appears at position 0 in the string
your if(strpos == true) returns a false.
Thats because == doesnt check the datatype and 0 is considered as false.
Anyway great plugin – saved me alot of work.
Greets from Germany
Maik
Is it possible to make a hyper image link to the page instead of showing just the image
Amazing plug-in! Well done, and thanks.
Now, if only I could get it to work. The ultimate aim is to show a thumb (if image in post exists) next to the post title on the main page, with the thumb serving as a hyperlink to said post. But I just can’t get thumbs to display at all – nothing, not even a hint that something should be there.
I’m using a theme plug-in for WordPress, and editing the index.php file – that’s correct isn’t it?
Code looks like this at the moment. I’m a complete noob at php so please forgive any glaring errors on my part! I wish it was just as easy as activating the plug-in and ticking a few boxes ;)
“>
“>
” title=”contine reading “>Continue reading…
Posted by –
-
Ok, So I cant post code – whoops.
Some days ago I did something very similiar, not that flexible, but it was a quick solution to show thumbnails: I wrote a function that searches for the first img-tag in the post’s content, deletes it’s style information and takes it to build the img-tag of it’s thumbnail.
Doing it this way, your WordPress won’t be slowed down (see the comment of tricky)
In my case, I wrote it for a blog with the Xinha4WP-WYSIWYG-Editor in use, so are some differences how thumbnails are built:
Xinha4Wp: Original image “example.jpg” –> Thumbnail “.example.jpg”
WordPress: Original image “example.jpg” –> Thumbnail “example.thumbnail.jpg”
Xinha4Wp: Builds thumbnails for every image
WordPress: If the image is to small, there is no thumbnail built
So notice: The following code has to be modified when using the WordPress attachment system.
Example “category.php” (I hope, the code will be displayed correctly, it seems not to be possible to post code here)
<?php get_header(); ?><?php
function return_ThumbNail($Thumb) {
if (preg_match("/<img[^>]*>/",$Thumb,$Treffer)) {
// The first image is found. Delete all style-information etc.
$Thumb = preg_replace("/(<img ).*(src=\"[^\"]*\").*( \/>)/",'$1$2$3',$Treffer[0]);
// Following line only works with Xinha4WP
// Modify it when using the WordPress attachment system
$Thumb = preg_replace("/(.*\/)(.* \/>)/",'$1.$2',$Thumb);
return $Thumb;
} else {
return false;
}
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="Posting">
<h1><?php the_title(); ?></h1>
<?php
$ThumbNail = return_ThumbNail(get_the_content());
if ($ThumbNail) {
echo '<div class="Previes">'.$ThumbNail.'</div>';
}
the_excerpt();
?>
<p><small><a href="<?php the_permalink(); ?>">... read more!</a></small></p>
</div>
<?php endwhile; else : ?>
<div class="Posting">
<h1>Coming soon!</h1>
<p>No posts in this category, yet.</p>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Okay, there are still things to improve – this function does not catch errors, if the thumbnail-file doesn’t exist or if the image-tag is built with single-quotes instead of double-quotes etc. – But it runs quickly and might be an alternative for those having trouble with their performance.
(Please excuse my bad English, my German Posting might be better to understand …)
pufaxx – this is working except it does not seem to include “thumbnail” before the image
example:
Yes, you’re right – but as I wrote: this is a “quick solution” for the Xinha-Editor.
:-)
Using the WordPress uploader, the second preg_replace has to be modified – and it might be useful to check, if a file like “example.thumbnail.jpg” really exists: WordPress does not build thumbs from images that are as small as the thumbnails would be …
… This code should work with WordPress (I hope so):
function return_ThumbNail($Thumb) {
if (preg_match("/<img[^>]*>/",$Thumb,$Treffer)) {
$Thumb = preg_replace("/(<img ).*(src=\"[^\"]*\").*( \/>)/",'$1$2$3',$Treffer[0]);
$Thumb = preg_replace("/(.[^.]* \/>)/",'.thumbnail$1',$Thumb);
} else {
$Thumb = false;
}
return $Thumb;
}
:-)
Hello there,
one more “great work” from me for your smashing plug-in.
I tried the post_image_multiple()-function shown in Thom Meredith’s post above that displays all images in an post. Unfortunately it didn’t work for me in WP 2.1.
Here is a version of “post_image_multiple()” that works for me. This function displays thumbs of all images attached to a post and automatically creates links for a lightbox-slideshow (lightbox has to be installed and configured).
It might need some improvement but i hope it is of some use.
Just put the the following code at the end of your post post-image.php file.
function post_image_multiple($default_image='', $use_thumb=true, $img_tag=tue, $css_class='post-image', $customkey='post-image', $display=true) {
global $post, $posts, $wp_version, $wpdb;
global $post_image_attachments;
if( empty($post) )
return;
if( !empty($posts) ) {
foreach($posts as $apost) {
if( $posts[0] != $apost )
$IN_ids .= ',';
$IN_ids .= (int) $apost->ID;
}
}
$post_custom = get_post_custom($post->ID);
$meta_value = $post_custom["$customkey"][0];
if( $meta_value ) {
$img_url = $meta_value;
$img_title = apply_filters('the_title', $post->post_title);
} else {
if( empty($post_image_attachments) ) {
$record = ( $wp_version get_results("SELECT ID, post_parent, post_title, post_content, guid FROM $wpdb->posts WHERE post_parent IN($IN_ids) AND $record = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY post_date ASC");
}
#echo sizeof($post_image_attachments);
foreach( $post_image_attachments as $attachment ) {
#echo "in foreach";
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
$postmarked = strpos(strtolower($attachment->post_title), strtolower($customkey));
$fileimage = explode('.', basename($attachment->guid));
if( $postmarked == true || $post->ID == $fileimage[0] || $post->post_name == $fileimage[0] ) {
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
if($postmarked == true) {
$img_title = trim(str_replace($customkey, '', $img_title));
break;
}
}
if( $use_thumb && ($img_url != $default_image) )
$img_url = preg_replace('!(\.[^.]+)?$!', __('.thumbnail') . '$1', $img_url, 1);
$img_path = ABSPATH . str_replace(get_settings('siteurl'), '', $img_url);
if( !file_exists($img_path) ) {
return;
} else {
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image_link_url_array = explode('/', $img_url);
$image_link_filename = $image_link_url_array[sizeof($image_link_url_array) - 1];
$length_thumb_name = strlen($image_link_filename);
$image_link_filename_array = explode('.', $image_link_filename);
$image_link_filename = $image_link_filename_array[0] . '.' . $image_link_filename_array[sizeof($image_link_filename_array) - 1];
unset($image_link_url_array[sizeof($image_link_url_array) - 1]);
$image_link_url = substr($img_url, 0, strlen($img_url) - $length_thumb_name) . $image_link_filename;
$image = '';
} else {
$image = $img_url;
}
}
if( $display )
echo $image;
# return $image;
}
if( !empty($default_image) && sizeof($post_image_attachments) == 0 ) {
$img_url = $default_image;
$img_title = apply_filters('the_title', $post->post_title);
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image = '';
}
if( $display )
echo $image;
}
}
}
HM. a- and img-tags seem to be cut out in code-postings. Does anybody know how it is possible to include them into a comment?
thanks so much pufaxx works perfect!
Next try :)
Put these code lines in your post-images.php file and call post_image_multiple() from your WP-template. Uses thumbs generated by the WP-upload mechanism.
function post_image_multiple($default_image='', $use_thumb=true, $img_tag=tue, $css_class='post-image', $customkey='post-image', $display=true) {
global $post, $posts, $wp_version, $wpdb;
global $post_image_attachments;
if( empty($post) )
return;
if( !empty($posts) ) {
foreach($posts as $apost) {
if( $posts[0] != $apost )
$IN_ids .= ',';
$IN_ids .= (int) $apost->ID;
}
}
$post_custom = get_post_custom($post->ID);
$meta_value = $post_custom["$customkey"][0];
if( $meta_value ) {
$img_url = $meta_value;
$img_title = apply_filters('the_title', $post->post_title);
} else {
if( empty($post_image_attachments) ) {
$record = ( $wp_version < 2.1 ) ? 'post_status' : 'post_type';
$post_image_attachments = @$wpdb->get_results("SELECT ID, post_parent, post_title, post_content, guid FROM $wpdb->posts WHERE post_parent IN($IN_ids) AND $record = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY post_date ASC");
}
#echo sizeof($post_image_attachments);
foreach( $post_image_attachments as $attachment ) {
#echo "in foreach";
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
$postmarked = strpos(strtolower($attachment->post_title), strtolower($customkey));
$fileimage = explode('.', basename($attachment->guid));
if( $postmarked == true || $post->ID == $fileimage[0] || $post->post_name == $fileimage[0] ) {
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
if($postmarked == true) {
$img_title = trim(str_replace($customkey, '', $img_title));
break;
}
}
if( $use_thumb && ($img_url != $default_image) )
$img_url = preg_replace('!(\.[^.]+)?$!', __('.thumbnail') . '$1', $img_url, 1);
$img_path = ABSPATH . str_replace(get_settings('siteurl'), '', $img_url);
if( !file_exists($img_path) ) {
return;
} else {
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image_link_url_array = explode('/', $img_url);
$image_link_filename = $image_link_url_array[sizeof($image_link_url_array) - 1];
$length_thumb_name = strlen($image_link_filename);
$image_link_filename_array = explode('.', $image_link_filename);
$image_link_filename = $image_link_filename_array[0] . '.' . $image_link_filename_array[sizeof($image_link_filename_array) - 1];
#echo $image_link_filename;
unset($image_link_url_array[sizeof($image_link_url_array) - 1]);
$image_link_url = substr($img_url, 0, strlen($img_url) - $length_thumb_name) . $image_link_filename;
$image = '<a href="' . $image_link_url . '" title="' . $img_title . '" rel="lightbox[slideshow]"><img class="' . $css_class . '" src="' . $img_url . '" ' . $imagesize[3] . ' title="' . $img_title . '" alt="' . $img_title . '" /></a>';
} else {
$image = $img_url;
}
}
if( $display )
echo $image;
# return $image;
}
if( !empty($default_image) && sizeof($post_image_attachments) == 0 ) {
$img_url = $default_image;
$img_title = apply_filters('the_title', $post->post_title);
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image = '<img class="' . $css_class . '" src="' . $img_url . '" ' . $imagesize[3] . ' title="' . $img_title . '" alt="' . $img_title . '" />';
}
if( $display )
echo $image;
}
}
}
Post-Image doesn’t seem to work inside my custom (page-)templates – no image shows up although the same code works fine in my “index.php”, “page.php” and “single.php”. :-/
—[no special usage in my custom template...]—
$thumb = szub_post_image(‘&use_thumb=1&display=0&css_class=neuigkeit’);
echo $thumb;
—
Is this a general problem of post-image in custom page-templates (WP 2.0.7) or did I miss something?
I would appreciate every little clue.
Bernd
I just installed and got this working nicely and it’s JUST what I need! (HUGE Thank You!) However, I’ve got one little problem. Is there a special way I have to write this to get the image tag to not generate in posts that don’t have an assigned image? I just downloaded, so I have the most recent version of your plugin, and I thought that wasn’t supposed to happen.
Running on testbed here:
Testbed (this is 2.0 WP install, it’s just for quick testing of themes, and I never updated, so tell me if that is the problem and slap me :-))
I tried to post my template code but couldn’t get it to show, so I’m getting creative here. This is what I have between the php opener and closer on the index.php and the single.php templates — post_image(”, false);
And on the archive.php template I have this– post_image(”, true);
As you can see from the border showing, the image tag is there, even though it shouldn’t be on the imageless posts.
Thanks in advance for your help.
Hello, there are some problems with this plugin:
In my index.php there is following code:
have_posts()) : $my_querytest->the_post();
$do_not_duplicate = $post->ID; ?>
">
" rel="bookmark" title="">
But images are not displayed.
I think that there are some problems with date of publishing and date of adding images.
Because I had post from March and today I added image to this post. But no image was displayed. But when I changed date of this post (today), then it works…
It is very strange…
And when I copy these code into category template file, then images are displayed OK.
Could you please help me, somebody?
Thank you very much…
I am sorry, code was bad formatted:
$my_querytest = new WP_Query('showposts=4&cat=3,4,11');
while ($my_querytest->have_posts()) : $my_querytest->the_post();
$do_not_duplicate = $post->ID;
post_image('http://www.admentour.cz/wp-content/uploads/test.png');
And then there is code with posts…
And in my sidebar there is this error:
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND post_type = 'attachment' AND post_mime_type LIKE '%image%]
SELECT ID, post_parent, post_title, post_content, guid FROM wp_posts WHERE post_parent IN() AND post_type = ‘attachment’ AND post_mime_type LIKE ‘%image%’ ORDER BY post_date ASC
Thank you very much for your help…
Reid Beel’s solution above worked for me when using ‘query_posts’.
Is it possible to use the tag twice in a loop – with a conditional to set different size for post_image?
To fix the Invalid argument supplied foreach() error, replace lines 82 – 103 with the following code
//! FIX to prevent error: Invalid argument supplied foreach()if (!empty($post_image_attachments)) {
foreach( $post_image_attachments as $attachment ) {
if( $post->ID == $attachment->post_parent ) {
if( !$first_attachment ) {
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
$first_attachment = 1;
}
$postmarked = strpos(strtolower($attachment->post_title), strtolower($customkey));
$fileimage = explode('.', basename($attachment->guid));
if( $postmarked == true || $post->ID == $fileimage[0] || $post->post_name == $fileimage[0] ) {
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
if($postmarked == true) {
$img_title = trim(str_replace($customkey, '', $img_title));
break;
}
}
}
}
}
To stop showing an empty tag (aka the Evil Red X in IE) look for the following code:
$img_path = ABSPATH . str_replace(get_settings('siteurl'), '', $img_url);if( !file_exists($img_path) ) {
return;
and replace it with:
//! FIX: Prevent display of tag if there is no image.
$img_path = str_replace(get_settings('siteurl'), '', $img_url);
if (empty($img_path))
return;
$img_path = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH . $img_path);
if( !file_exists($img_path) ) {
return;
Kaf (or anyone else for that matter) I have a fixed file that doesn’t show empty image tags. Contact me through my website if you’d like a copy. The fix was courtesy of Vix
I’m using 2.1 and got the post_image() to show thumbs.
You need to pass in a default image to use, it can be total nonsense – just needs to be there.
I used:
post_image('na', true);Hope that helps.
ET
When using post_image on the index, it works beautifully. When using it on a template page, though, it generates an empty src tag. Any ideas what may be causing this?
Is there a way to exclude certain posts from containing an image, even if there’s an image uploaded? I tried using a custom key, but that only lets me choose between a specified or just the default first uploaded image.
it works with images from flickr? thanks!
Question, an image in my post is:
I gave it the ‘post-image’ text
In my category.php file I added both
(i used both as a trial and error)
the problem is i’m still getting the FIRST picture of each post instead of the assign ‘post-image’ picture. Any idea what i’m doing wrong?
Also, what would be the reason for this plugin NOT showing the first image on the post? It does for most of my posts, but some of them it shows the 2nd or 3rd image instead.. weird. Any ideas?
Is there a way to display the image attachment from the thumbnail of the wordtube?
Hi there!
When I try to activate the plugin I get a warning that says:
“Plugin could not be activated because it triggered a fatal error.”
uh…?
Thanks!
dear sir . thank you again for writing this plugin . two things if i may .
1) this line hangs my page
$imagesize = @getimagesize($img_url);if i replace it thusly, it works beautifully
$imagesize = @getimagesize($img_path);the last entry on this post aided me in locating the error
http://www.webmasterworld.com/forum88/4341.htm
2) i saw mentioned early in the discussion that you refer to that initially caused you to write this plugin, some one mentioning the ability to create a set of images rather than just one . i am about to set out to try and solve this part of the puzzle . i wonder if you have any tips on direction before i begin ?
Hi all,
I just needed to show a few posts(with images) in single.php, I use somethig like this:
<?php
$thumbs = new WP_Query("cat=1&showposts=4");
while($thumbs->have_posts()) : $thumbs->the_post(); ?>
<img src="<?php post_image('http://www.wowebmaster.com/wp-images/imgcomingsoon.gif', false, false, '', 'customkey', true); ?>"/>
<?php the_title(); ?>
<?php endwhile; ?>
But instead of displaying the post’s attachment, the code displays always the default image.
My test page: http://www.wowebmaster.com/aq
Can anyone help? It’s about to be morning,and I’m lost!
Hi! great plug.
Where ca i put a strreplace fot the title. Cause i have some problem with the Polyglot plug installed on the site. I can’t delete the tags of languages display in the title.
hi I am using WP 2.2 and I am having trouble getting this plugin to work on my category.php template. When I add the code template, it only displays the first post in the category. Has anyone else had this problem or know how to fix it?
Whoa after spending many hours of teeth gnashing I finally got this to do what many of us want. A Loop with a single post with a full post_image and then another Loop with a bunch of excerpts and their assoc post_image thumbnails.
First I want to give props to Reid Beels whose little posting midway down this page really made the difference in my case…
replacing the globals call at the top of the post_image.php doc with :
global $post, $wp_version, $wpdb, $wp_query;
global $post_image_attachments;
if($wp_query->posts!=$posts)
$post_image_attachments='';
$posts = $wp_query->posts;
then when I did a 2nd query_posts() Loop I was able to simply include the usual
post_image('',TRUE);and got thumbnails for each of the queried posts.
I am still having troubles with the default image inclusion not displaying anything. If I put
post_image('/path/to/default.jpg',TRUE);nothing shows up- no img src nothing
but if I keep it empty
post_image('',TRUE);the image shows up just fine.
if anyone has any ideas that would be great.
thanks
JS
Hello, nice work dude!
I am running MAMP on OSX and don’t see any images when I use the plugin, it seems to be picking up /Users/myusername/mymampfolder/blahblah as the url for the images. Any ideas?
I am hoping to display multiple images as well. Fingers crossed!
I am using your plugin to display images with my excerpts. Sometime the images display and sometimes the just show the default even when there is a picture. I cannot figure out why. Do you have any ideas? Thanks for any help.
Since upgrading to 2.2.1 the plugin has started to behave strangely. Older posts still display the thumbnails. New posts display the full size image. Example is here. Anyone having something similar occur?
Also getting some strange stuff going in 2.2.2 — was working fine 2.2 but now acting up. I can provide more specifics if needed. Any idea if this excellent plugin will be tested/fixed moving forward?
Is this plugin compatible with WP 2.1? How can I set alignments with this plugin?
Great thanks for the plugin. :)
-Nish
any plans on making this compatible with 2.2? that’d be awesome, thanks!
It looks like this plugin stores the image URL as a full path which means you cannot easily move the site to a new domain/test domain.
Also it won’t work under SSL. Maybe due to the same issue.
Anyway to get this to use relative paths? Fix the SSL display issue?
We’re on 2.2.1 by the way
Great Plugin. I used php post_image(); but i get no images. when i look at the code i see a bunch of image tags with no values in the src attribute. help?!
Hi I’m having the same problem of empty src attributes in the resulting code.
Any ideas of how this can be fixed. I’m on WP 2.2.2
This plugin is working just great for me, as you can see on my site. However, the ‘Recent Posts’ script in the footer uses a second Loop called through a WP_Query, and the Post Image plugin behaves oddly here. If the a post listed in the ‘Recent Posts’ section is also called within the main Loop, then the Post Image will display correctly. But, if the a post that is listed within the ‘Recent Posts’ script *isn’t* called within the main Loop, the Post Image script won’t display the respective post image – it’ll just show the default post icon. It seems that the first Loop is calling something that the second, ‘Recent Posts’, Loop isn’t calling.
Hi – please verify this for me before I start – This works with WP 2.1 AND, since I use Photopress, the images are html in the content – will post-image extract the image and thumbnail size it ?
Thanks for your help
PS Any good examples of code – I need the title and thumbnail only to appear on a static html page…
hello! i have a small question regarding the attached images to a post. as long as i changed the title to post-image via the browse category the image is n olonger ”attached“ to the post. therefore it will not display as a post image…it would be very helpful if every image in the ”uploads“ folder could be – depending on their title – be a post-image without being attached to a post.
is this feature planned or am i missing something here?
best regards,
christopher
I downloaded the last version and tried it on WP 2.3. It was not working, so I check the code of the plugin, and the line that was not working was $imagesize = @getimagesize($img_url); I´ve changed $img_url for $img_path and the plugin is working fine. Kaf, why do you use $img_url instead of $img_path?
Thank you for the plugin!
Does anyone know how to exclude first image from post_image_multiple()?
Thanks for this plugin, it was almost exactly what I was looking for! I extended your code with image-resizing on the fly functions, and connected all this to Slimbox. Works just as I wanted it. You can see the site here: http://hard-guild.com
Fantastic plugin, but just wondering if it’s causing problems with the admin section of the latest (2.3) wordpress? While this plugin is activated, any page that submits data via post results in a blank white screen. Anyone else experiencing this?
I’m using this plugin in WP 2.3 to display a floated image with caption (modified plugin return a little). Problem is, on my home page I need to use get_posts() in order to exclude some things, and if the exclude parameter is used, the WP global option for number of posts per page affects return of images. If I page through lots of results, I see sequences of posts where the plugin fails to return an image. Without the exclusion parameter in get_posts(), this does not happen. And changing the max posts per page affects where the gaps occur.
Just wanted you to be aware of that if updating the plugin. Thanks!
I’m confused on how to pick which images show up. I can get the first image to show up by adding post-image to the alt of the image. But I can’t get the image to show up on the next post. What do I need to put in the post to get an image to show up?
Thanks for your help.
I figured out the problem…it is showing the image for the first post in a list, but not the rest. Please see my website cricketsoda.com.
hi, thank you for this plug-in. is there a way to show all images that are attached to a post rather than just one? i’ll be sure to make a donation if i can get this functionality :)
I can’t seem to get it to work inside a random list of posts:
<?php
global $post;
global $wpdb;
$numposts = 2;
$rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_parent = '4' ORDER BY RAND() LIMIT $numposts");
foreach($rand_posts as $post) :
setup_postdata($post);
?>
<div id="hogarenas">
<a href="<?php the_permalink(); ?>"><?php post_image('', true, true); ?></a>
<h3><?php the_title(); ?></h3>
<?php the_content_rss('', TRUE, '', 13); ?>
<a href="<?php the_permalink() ?>" title="Ver más sobre: <?php the_title(); ?>">más »</a>
</div>
<?php endforeach; ?>
It is inside a loop. Any ideas?
Thanks in advance.
hello! i have the same problem since update to wp 2.3 the plugin doesn´t work. old pictures are shown, but new ones not. i found out, that the reasen is in the database at the fields “post_name” and a second field in “posts” where the image_title should be, but there is nothing?!? sorry about my bad english, but i am from austria ;-)
can anyone help??!?!?
Hi, can you please tell us how to make the thumbnail be inserted in the text and make it wrap around the thumbnail? This is the only thing I miss in this wonderfull plugin!!!
I am having problems with it taking away an image upon posting into a different category. I only want it to pull an image if the latest post was from a specific category. Any help please!!!!
Hi,
I need to do something like:
if ( post_image() ){
[a class="post-image-link" href="[?php the_permalink() ?]“][?php post_image(); ?][/a]
}
but I don’t know what to use as my qualifier – am I being retarded? I don’t want a default image, otherwise I’d just use post_image() on it’s own…
sgu, I have exaclty the same problem. has anyone found a solution?
I think I found where the problem is – on line 84:
if( $post->ID == $attachment->post_parent ) {$attachment->post_parent is not updated properly when post_image is used in single.php instead $attachment->post_parent keeps the parent of the current post.
Now if somebody has an idea how this can be fixed, it would be great :)
im using wp 2.3.1 and post image and it works
I am having the same problem as Camilo above. In a custom query, this plugin does not seem to work.
I think that Camilo, sgu, Derek and me we have the same problem. Anybody help? Kaf?
Hi,
Great work on this plugin and post_image_multiple().
Thanks.
Hi,
Great Plugin.
It looks fantastic on the spanish news website http://www.knvotv48.com Except for one small item
In the left sidebar I list the most recent story headlines using the post_image, and everything looks great.
However when I click on a story to go to a single post, the left sidebar (while still showing all the latest headlines) will only show the default image with the exception of the current story being viewed.
Please help me solve this. I just need the sidebar images to stay consistent throughout the site.
Thanks
@ Anthony
As Reid Beels has pointed out; you need to edit a couple of lines in the post-image.php file so that the plugin always works outside the Loop. I’ve documented my problems and the fix on another forum;
http://www.webdeveloper.com/forum/showthread.php?p=845581#post845581
Thank you, this plugin is exactly what I needed to get the look’n'feel for my photography blog. It is simple and fast, and it really really works. A lovely piece of work, again, thank you!
Tom
Hi, I just downloaded and installed your plugin into a blog I am working on, but it I ran into a problem. I use WP 2.3.1 modified K2-vader. I checked on how Post Image’s functionality would work with the live search feature of K2 and live search doesn’t seem to like Post Image in the search results.
here’s what i get
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND post_type = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY post_d' at line 1]
SELECT ID, post_parent, post_title, post_content, guid FROM wp_posts WHERE post_parent IN() AND post_type = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY post_date ASC
Hi Kaf,
I’m trying to get your plugin to work with post lists on WordPress Page Templates. I’m using the post_image tag within the loop, and it doesn’t seem to work; an image tag is created, but there is no src data in the tag.
I tested by using the same code in the home page and a category, and the Post Image tag works fine. I’ve been stuck on this for hours!
Is it possible for the post-image plugin to work on page templates? Is there a small change I can make in the code that will allow it to work?
I’m not much of a programmer, but I can get in there and edit. Any help would be greatly appreciated, thanks!
@neil, thanks your solution solved my problem!
I’m still getting the ‘broken image’ stuff when no image is attached. Only in Internet Explorer though.
I’m quite dependent on Post Image — and am sad to see that I have problems with it in WP 2.5 now. Images that were attached to posts in ≤2.3.3 work fine with PI, but any image that I attach using 2.5 don’t get pulled up by PI. Do you have a fix or even work-around for this? (Or another way, or even another plugin to recommend, to achieve PI’s powers in WP 2.5?) I’ve had to roll back my installation for now, since I really must have thumbnails on index pages, as PI makes possible.
@ Jon,
I to am quite dependent on Post Image. I have upgraded most of my blogs and am still using Post Image with success (limited success).
The problem was that in 2.5 when thumbnails are created, if you look in the uploads folder, they are no longer called .thumbnail, the thumbs are now titled according to their size. In addition to the full size image you upload, there are now two thumbs or additional images created, a thumbnail and a medium image. The thumbnail can be “Crop thumbnail to exact dimensions (normally thumbnails are proportional)”, the default setting is 150×150. So when a thumbnail is created it no longer has .thumbnail in its title but -150×150. (or whatever you change the size to)
The medium image does the same, except it does not make square, so the size will vary depending on the size of the original image, hence the title of the image will change depending on the size created.
What I have done to use this on a couple of my sites I went into in the post-image plugin and around line 110 changed this line
if( $use_thumb && ($img_url != $default_image) )$img_url = preg_replace('!(\.[^.] )?$!', __('.thumbnail') . '$1', $img_url, 1);
I swapped out the .thumbnail for -150×150 and it works just fine.
Also, I have noticed that when the gallery function is used to add a gallery to a post, the plug-in will display one thumb from the gallery.
An issue I have noticed, is that when the gallery function is used with this plugin in conjunction with the_excerpt tag or with Kaf’s the_excerpt_reloaded plugin, there are several lines of inline css that are displayed along with the thumbnail. This was briefly discussed on the wp test list and I think it is in the trac, not sure of much else.
Thanks for that hack, hack works perfect. I hope this update gets some update love and adds support to be set to what ever the thumbnail dimensions settings it set at automatically….. maybe not though.
i need make so:
http://img232.imageshack.us/my.php?image=20080419185159sg6.jpg
first image show as full reolution and other thumnails as links to post
Or you know similar plugin?
thanks.
Thanks, Aaron, for the informative reply and good advice. Let me update you and other readers with my experience, since some may find it useful.
Your hack does indeed work, and I recommend it to other users. It’s an easy fix. But there are two reasons it’s not the perfect solution for me: (1) It allows post-image to display thumbnails for _newly uploaded_ images only (which get named with WordPress’s new file-naming convention). All my old posts lose their images if I hack post-image in this way. (2) I’d rather not use the square WP thumbnails, but the proportional ones — but since I (like most of us) often post both landscape and portrait-oriented images (and occasionally ones of different aspect ratios entirely), I can’t predict what the dimensions of the non-square WP-generated thumbnails will be, so I can’t hack post-image directly.
I considered hacking WordPress itself, and making it name thumbnails with “.thumbnail” in the name (as post-image expects), and was successful — but this then plays havoc with how WP itself displays thumbnails in various places, and of course then I’d have to keep re-hacking WP every time there’s an upgrade, so I ditched that experiment.
In the end, what I’m doing is using post-image’s own ability to use a custom field in WP to get the URL of the thumbnail I want. This is a hassle, since I have to manually enter WP’s thumbnail URL into each post that I want to display an image for, but it is 100% reliable. (And it’s a feature of post-image I had been unaware of previously, actually.) All you have to do is enter “post-image” in the custom-key field and then the URL of the thumbnail in the “value” field right in a WP post page.
At least for the time being, I’m glad to have a workable solution — but I do dearly hope that Kaf (or someone else, with more php/WP skills than I) will update post-image to work with both generations of WP thumbnail naming conventions. (I still can’t believe that post-image’s functionality or something like it isn’t built right into WP, and that there’s no other plugin that I can find that does anything like it.)
Looks like you guys have answered my questions. I’ve been hesitant to upgrade my 2.2.2 WP version because I had a hunch that both “Post-Image” and “The Excerpt Reloaded” wouldn’t work with the new version. You guys are now confirming that hunch.
I’ll have to look at the suggested hacks above and see if they are workable. I’ve been afraid of this all along since both of these plugins seem to be abandoned. But, they are great solutions for something that WordPress should do out of the box (as mentioned earlier).
Any tips or tricks to port these over to the latest WP build would be appreciated. Thanks!
I got this working pretty much immediately, however, yes, the infamous however, oddly it pulls up a photo from another post.
Here’s the code I’m using to “pull” the ideal photo and respective link:
< ?php post_image('default_image', use_thumb, img_tag, 'css_class', 'customkey', display); ?>
Any ideas why it’s doing this? I’m using NextGen as my gallery.
BTW, thank you so much for this plugin. It’s frickin’ awesome and a total time saver for my clients…well, when I get it working properly.
Okay, scratch all that above…it was my wrong doing.
However, is there a way this plugin will work with the NextGen gallery, automatically? Meaning, it’ll grab the first photo of the post, then display it in the post summary?
Insert after line 106 this code:
if( $use_thumb && ($img_url != $default_image) )
//$img_url = preg_replace('!(.[^.]+)?$!', __('.thumbnail').'$1', $img_url, 1);
$attargs = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($attargs);
if ($attachments) {
foreach ($attachments as $attachment) {
$img_url= wp_get_attachment_thumb_url($attachment->ID);
$chkimg=wp_get_attachment_url($attachment->ID);
if($img_url==$chkimg){
$img_url = preg_replace('!(.[^.]+)?$!', __('.thumbnail') . '$1', $img_url, 1);
}
else{
$img_url = wp_get_attachment_thumb_url($attachment->ID);
}
break;
}
}
hi-
i have seen a few comments here and on the_excerpt reloaded page that ask how to get text to wrap around the image, but i can’t seem to find the answer to that question. i am using these two plugins in a mini-loop on my static homepage, but i cannot get the excerpt text to wrap around the image. i am assuming this is a stylesheet issue… i put a line in the stylesheet for post-image to align:left; display:inline; per a wordpress forum post but that didn’t work.
is there a way to get this to work? my home page just doesn’t quite look right to me as it is now.
thanks so much!
I updated the code of Post Image so that it works with WordPress >= 2.5 still being backward compatible so you don’t have to update older images names and metadata. Here’s the link: http://vinicius.biz/blog/post-image-plugin-updated-to-work-with-wordpress-25/
This is really weird…I had this working very well, was just loving it. Then I moved it to my client’s hosting account, which is under the same host, but on a different server I think, and now it won’t pull up the images. I didn’t change anything. All the other plugins work fine, just not this one now. It’s bumming me out ’cause I just love this plugin, it really brings life to a site.
I’m using WP 2.3.1, maybe I should upgrade to 2.5x?
Justin, is it at least printing the img tag? If so, check the image paths, because it might be referencing the images on the other domain (I guess your client uses another domain?). Even if the paths are correct, it’s possible the old account is blocking based on referer.
Dear friend
How can I resolve this problem:
Fatal error: Cannot redeclare szub_post_image() (previously declared in /web/htdocs/www.mgdiario.it/home/wp-content/themes/recycled-canvas-10/functions.php:89) in /web/htdocs/www.mgdiario.it/home/wp-content/plugins/post-image.php on line 38
Thanks
Great plugin, but doesn’t work completely for me. I can only get my pic when i use thumbnails in my actual post; meaning if i were to use the full pic, it doesnt work. Any ideas why? I’m using WP 2.5 and so i’m using the new version by Vinicius. i’m using the following code:
post_image(‘images/noevents.jpg’, 1, 1, ‘eventspicbox’);
Okay, I solved my issue; just in case anyone wanna know how i did it, here’s how: i realised that i needed multiple Loops on my code and when i used get_posts() it doesn’t work as well as query_posts(), after i read the comment by Neil from the comment above. He has a link to another forum that edits the post_images.php file and after following his and twitching, it works for me! Great job Neil.
@Michele: You use the recycled-canvas theme. There, with the recycled-data plugin, post_image is already defined as a function. So you need to either deactivate recycled-data plugin or the post-image plugin., because the function szub_post_image() can’t be defined twice.
@Vinicius and @Brandon : Vinicius.biz site is down so I can’t get the update post-image v1.2 you guys hacked. I have a wordpress 2.6 site to get up asap with post-image. Where can I download the updated version? Thanks to put it somewhere, I’m sure a LOT of people are looking for it ;)
My version is temporarily avaiable at http://www.bluff.com.br/post-image-1.2.zip
This plugin is hot stuff. Thanks. You can see our implementation @ http://ouripics.com
I can’t get the multiple image hack to work.
I think part of the problem is, when I copy it over, a lot of the quotes and such are “smart” and I have to replace them… I think the formatting is broken.
Or is it just not working in WP 2.6?
Great plugin btw!
Hi, I cannot get the plugin to work,here is my loop:
<?php if ($col == 1) echo “”; ?>
<div class=”post col” id=”post-”>
<a class=”link” href=”" rel=”bookmark” title=”Permanent Link to “><img src=”" />
In
<?php if ($col == 1) echo “”; (($col==1) ? $col=2 : $col=1); ?>
Is a simple one with a small trick to have posts in coloumns. The plugin doesn’t create tags or code , nothing.. used the example in this page and some tries changing parameters…
Where am I wrong??
Please I need help!!
Forgot to add and in previous post (the loop is ok I think)
Hey All
I made use of this great plugin but also had the speed problem mentioned above. After much agonising (and jumping to conclusions about the sql server etc) I added some speed tests to the code and found the single line that is causing the problem:
$imagesize = @getimagesize($img_url);
Now, on my server which uses CGI PHP this was taking between 3 to 5 seconds to return so a page with 10 posts was taking over half a minute to load – painful!
$imagesize value is referenced in the below line:
$image = ”;
Fix
I found a couple of fixes:
1 – comment out the problem line and remove the reference to it in the img tag. (For the squeamish replace the two lines above with the two lines below)
//$imagesize = @getimagesize($img_url); /* get rid of this with the comments as shown */
$image = ”;
2 – change the url in $img_url to a server path so:
change: “http://www.domain.com/images/filename.jpg”
to: “/public_html/blog//images/filename.jpg”
This changes the execution speed to fraction of a second rather than nearly 5.
When I get five minutes I will wrap this up in a new version and drop a linky.
Cheers
Marcus
Marcus, that is awesome, great find! Looking forward to the new version:)
Crikey, can anyone help a newby with this when using the recycled-canvas theme!
Where do I put the code exactly? DO I need to modify the theme in anyway first?
Which code should I use?
Thanks in advance!
Great plugin! Works great!
I have one question though.. when editing an existing post with a post image, the image is not listed in the post image section, and when saving the updated post, the image is lost. Does anyone else have this problem?
Also, is this plugin compatible with wp 2.7?
Hi Kaf,
was hoping you might be able to help with a little issue … I’m showing a image for each post on the index page, which is working fine, but when I try to list other posts on a post page, the image for the other posts don’t show. Is this because the plugin is trying to reference the image for the post i’m on? I’m able to grab the title and post ID for the ‘other’ posts, just not the post-image.
any help if you have time would be awesome.
on the original WP post, you wrote:
“* Displays first image attached to the post, or alternatively an image using either the postname (i.e. slug) or ID of that post for its filename; this is configurable through a parameter.”
what parameter do i need to change in order for it to display the image using the post name?
Hi,
Firstly, thanks for this plugin – a life saver.
My problem is that wordpress 2.5 changed the default name extension for thumbnail image and i think it’s screwing up. Is there a work around for this?? None of my thumbs are saved off as .thumbnail.jpg – which i think the script looks for?
Let me first say that this is a great tool and I am so happy I’ve found it. Unfortunately, I have somewhat of I strange situation where I want posts from a certain category to only appear in a small box in my sidebar. To accomplish this, I’ve inserted the following code at the top of the main index loop to ignore posts from this particular category within the main posts area:
However, the way your plugin works obviously is by taking images from whatever is the most recent post. So, what I’m trying to do is figure out how to get your plugin to also ignore posts from this certain category so that I do not get mismatched images/posts in the main index viewing area.
Thanks for your help.
kountz, you can change it by modifiing the code (WP Admin > Plugins > Post Image > Edit )
Scroll down to where you can see:
if( $use_thumb && ($img_url != $default_image) )
$img_url = preg_replace(‘!(\.[^.]+)?$!’, __(‘.thumbnail’) . ‘$1′, $img_url, 1);
}
and change it to:
if( $use_thumb && ($img_url != $default_image) )
$img_url = preg_replace(‘!(\.[^.]+)?$!’, __(‘-150×150′) . ‘$1′, $img_url, 1);
}
I just had the same issue.
Cheers,
Mike
This is a great plug in I used for a long time.
I recently switched to WordPress MU (2.71) and it stopped working on new posts. Curiously, it still works on posts with images added when the blog was single user. ( I successfully imported a single user WordPress install into a brand new WordPress MU) I hope to be able to figure this out because it worked so well before, and it was integral to the design of the blog.
Kilwag, any word on updating this plugin? Is this plugin still active?
@kilwag
Same for me.
I use grid-a-licious theme on a wp-mu site and i cannot use this plugin