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.
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.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.
Author: Kaf Oseo
Categories: WordPress
Comments: (185) · Leave a comment · Comments RSS2 · Trackback URL
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;