I wrote “2.9 beta 1” as WP version for this post. Seems to show up as 2.91.
When you upload your image, you should have the choice to insert it into your post and add as thumbnail. If you click on add as thumbnail, you should see it in a box on the left called Post thumbnail. Save your post and it should display correctly.
Thanks!
Now I only need to figure out how to output just the url for the original size image (without the <img /> tag).
Can’t see to do that with either of the following:
post_image(); get_post_image_id(); the_post_image(); get_the_post_image()
Are there more?
$img_id = get_post_image_id();
$original_img = wp_get_attachment_image_src ($img_id, 'original');
echo $original_img[0];
I benefited from some of the solutions Thank you all
Fairweb, thanks a lot for the help!
I thought this would lead me in the right direction, but I’m not succeeding with what I want to do.
I want to output:
<p><a href="originalsize.jpg"><img src"mediumsize.jpg" /></a></p>
using “post image” implemented in WP 2.9.
Preferably (not at all crucial), if the medium image is smaller or has the same size as I’ve set (500 px) in the “Media Settings” under “Image sizes” > “Medium images” only:
<p><img src"mediumsize.jpg" /></p>
has to be output.
Looking under “Changing the HTML output of the post image” here might help.
I’ll report back if I find a solution.
Is that what you wanted ?
<?php $img_id = get_post_image_id();
// orginal image
$original_img = wp_get_attachment_image_src ($img_id, 'original');
list($original_src, $original_width, $original_height) = $original_img;
// medium image
$medium_img = wp_get_attachment_image_src ($img_id, 'medium');
list($medium_src, $medium_width, $medium_height) = $medium_img;
// option medium max width
$max_width = intval(get_option('medium_size_w'));
$begin_a = '';
$end_a = '';
if ($original_width > $max_width) {
$begin_a = '<a href="'.$original_src.'">';
$end_a = '</a>';
} ?>
<?php echo $begin_a;?><?php the_post_image( 'medium','class=alignleft' ); ?><?php echo $end_a;?>
Thank you! That is indeed exactly what I was after!
To add <p> and </p> before and after the snippet I tried inserting the <p>s here, but that only applies to the case where the picture uploaded is 500px wide or smaller.
$begin_a = '<p>';
$end_a = '</p>';
Sure I could add it to the html, but the best would of course be to only output the <p>s if there is a thumbnail image for the post.
Thank you once again!
an svn pull this morning broke my post image functionality (in my dev environment of course)
it looks like recently they refactored:
has_post_image -> has_post_thumbnail
get_post_image_id -> has_post_image_id
the_post_image -> the_post_thumbnail
get_the_post_image -> get_the_post_thumbnail
anyone who’s using the live source from subversion should make a note of this. all changes can be seen in wp-includes/post-thumbnail-template.php
Thanks for the update squaredesign !
I have made a plugin called fw-post-image using the_post_thumbnail()
which I have just updated according to squaredesign’s information.
I you use it, please let me know if you encounter any problem. You can leave comments on the plugin homepage.
Thanks
The 2.9 stable upgrade broke this whole thing for me too π
Tried changing according to squaredesign’s post but it still doesn’t work.
This is what it looked like when it worked (before the 2.9 upgrade and before I changed anything):
http://wordpress.pastebin.com/f2eb1728a
I upgraded, it didn’t work so I changed it to:
http://wordpress.pastebin.com/f7ecb43c0
and it still doesn’t work.
It says:
Fatal error: Call to undefined function has_post_image_id() in C:\Program Files\XAMPPlite\htdocs\wordpress\wp-content\themes\simpleserif\index.php on line 136
line 136 shows: <?php $img_id = has_post_image_id();
All is broken and help would be greatly appreciated.
This works.
<?php $img_id = get_post_thumbnail_id();;
// orginal image
$original_img = wp_get_attachment_image_src ($img_id, 'original');
list($original_src, $original_width, $original_height) = $original_img;
// medium image
$medium_img = wp_get_attachment_image_src ($img_id, 'medium');
list($medium_src, $medium_width, $medium_height) = $medium_img;
// option medium max width
$max_width = intval(get_option('medium_size_w'));
$begin_a = '';
$end_a = '';
if ($original_width > $max_width) {
$begin_a = '<a href="'.$original_src.'">';
$end_a = '</a>';
} ?>
<?php echo $begin_a;?><?php the_post_thumbnail( 'medium','class=alignleft' ); ?><?php echo $end_a;?>
Yes whiteout, as squaredesign mentionned it further up, the functions containing post_image
should now be post_thumbnail
. Obviously, you managed to make the suitable changes in your code. Well done.