Display The Thumbnail Of An Image (file)

0

As we all know, Wordpress automatically takes an uploaded image and duplicates into multiple image sizes. I'd like to be able to call the thumbnail of an associated event into my event_list template.

Help would be appreciated - thanks!

asked Dec 4 '09 at 3:38

jbrickman

13

add comment
enter at least 15 characters

11 Answers

1

I've never liked timthumb. You might try using this wordpress function:

http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

This assumes that Pods assigns an attachment id when a file is uploaded. I haven't tried it so I can't say for sure whether it does.

You might also try:

http://www.maverick.it/en/tech/create-thumbnails-using-wordpress-built-in-functions

answered Dec 2 '09 at 11:35

Mike Van Winkle

219

add comment
enter at least 15 characters
0

Try http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/

answered Oct 16 '09 at 10:42

Tárcio Zemel

1

add comment
enter at least 15 characters
0

Thanks for the tip about timthumb. I have been trying to set it up for pods for hours now but can't seem to get it to work.

After having followed instructions on multiple forums - set the timthumb folder permission to 755 and file to 644 as well asked hostgator to whitelist my domain (all these have been specific to hostgator as recommended by various forums) but the thumbnails still don't show, just the alt tag. Removing the timthumb script call in Firebugs shows the original image so I know that the path is correct. Any advice would be great! The link where this can be checked is http://buzzr.in/deals/ha-moving-sale (for testing, I have hardcoded the image link).

I am wondering if there is some kind of incompatibility with pods and Timthumb. If anyone has been able to get timthumb and pods working, please help me out. Thanks!

answered Nov 25 '09 at 6:46

kunal17

11

add comment
enter at least 15 characters
0

Have you tried using Timthumb on your local machine?

answered Nov 30 '09 at 8:16

logikal16

249

add comment
enter at least 15 characters
0

Unfortunately, I don't have a local setup (wouldn't know how to go about setting it up, I'm just starting out with all this :))

answered Nov 30 '09 at 1:09

kunal17

11

add comment
enter at least 15 characters
0

Thanks for the tip @mpvanwinkle. Ill give these a try.

I think I read somewhere that assigning thumbnails the way wp does it has not been added to pods yet.

answered Dec 3 '09 at 4:25

kunal17

11

add comment
enter at least 15 characters
0

I think using the built in resize functions is only possible with images linked to a post in WP (atleast according to the author of the blog link you recommended).

I tried using this function but am getting an error (http://buzzr.in/dealslist2)

The code that I am using (in a display helper is) <pre> $thumb = image_resize($value,25,25,true); $imagetag2='<img src="'.$thumb.'" alt="int">'; echo ($imagetag2); </pre> where image_resize is the internal function I have referenced the image api using require_once(ABSPATH . '/wp-admin/includes/image.php'); in functions.php

Any clues as to what I can try next?

Thanks.

answered Dec 3 '09 at 8:15

kunal17

11

add comment
enter at least 15 characters
0

@kunal17 - For starters, check your error log to see if there's anything in there. Then, try to also include the following above your "image.php" include:

<pre>require_once(ABSPATH . '/wp-includes/media.php');</pre>

image.php contains some image manipulation functions, but media.php is the file that contains image_resize().

answered Dec 3 '09 at 8:33

logikal16

249

add comment
enter at least 15 characters
0

Thanks for the suggestion. I tried that but I still get this error:

Catchable fatal error : Object of class WP_Error could not be converted to string in <b>/home/kunal17/public_html/buzzr/wordpress/wp-content/plugins/pods/core/Pod.class.php(302) : eval()'d code</b>

answered Dec 4 '09 at 3:38

kunal17

11

add comment
enter at least 15 characters
0

Hi.. when uploading a image from a pod entry, wordpress automatically generates 3 sizes. I have a solution for displaying them. Wordpress names these files like this: NAME-IMG-50x50.jpg (50x50 is the specified size at settings > media).

You can display this image like this: <img src="<?php echo substr($pod_image, 0 , -4);?>-50x50.jpg">

$pad_image is the var for get_field('NAME OF FIELD');

substr 0, -4 deletes the last 4 digits from your string. Than simply add the size.jpg and your done!

Hope this is helpfull..

answered Apr 28 '10 at 12:45

wouterjr

1

add comment
enter at least 15 characters
0

There's an alternate way to do this using built-in WP function "wp_get_attachment_image_src":

<?
$oProjects->fetchRecord());
//change "image" for your file filed name, but leave ".ID" after it
$iImageID = $oProjects->get_field('image.ID');
//last parameter can be thumbnail, medium, large or full
$arImage = wp_get_attachment_image_src($iImageID,'large'); 
$strImageSrc = $arImage[0];
$iImageWidth = $arImage[1];
$iImageHeight = $arImage[2];
?>
<img src="<?php echo $strImageSrc; ?>" height="<?php echo $iImageHeight; ?>" width="<?php echo $iImageWidth; ?>" />

I think this is preferable because it doesn't hard-code the image dimensions you're using. In the above example, if you changed your thumbnails from 50X50 to 75X75 in the WP Admin > Settings > Media page, the code would break, whereas it will still work using this technique.

answered May 28 '10 at 2:00

wpries

11

edited May 28 '10 at 2:02

Great solution, wpries. I've modified this to use the wp function get_attachment_url, which pull the latest version of the file saved by the WP Media Library instead of the source. This'll allow CMS users to manipulate and crop images using built-in WP 2.9 functionality. Voila: Easy cropping. It's still pulling size information from the source attachment, so I'm not sure if there's a more efficient way of making this happen instead of pulling from the database twice. <code> <? $oProjects->fetchRecord()); //change "image" for your file filed name, but leave ".ID" after it $iImageID = $oProjects->get_field('image.ID'); //get the latest saved crop for the image rather than the original source $metaurl = wp_get_attachment_url( $iImageID); //last parameter can be thumbnail, medium, large or full $arImage = wp_get_attachment_image_src($iImageID,'large'); $iImageWidth = $arImage[1]; $iImageHeight = $arImage[2]; ?> <img src="<?php echo $metaurl; ?>" height="<?php echo $iImageHeight; ?>" width="<?php echo $iImageWidth; ?>" /> </code> – okidoki232 May 29 '10 at 2:21
Great solution, wpries. I've modified this to use the wp function get_attachment_url, which pull the latest version of the file saved by the WP Media Library instead of the source. This'll allow CMS users to manipulate and crop images using built-in WP 2.9 functionality. Voila: Easy cropping. It's still pulling size information from the source attachment, so I'm not sure if there's a more efficient way of making this happen instead of pulling from the database twice. <code> <? $oProjects->fetchRecord()); //change "image" for your file filed name, but leave ".ID" after it $iImageID = $oProjects->get_field('image.ID'); //get the latest saved crop for the image rather than the original source $metaurl = wp_get_attachment_url( $iImageID); //last parameter can be thumbnail, medium, large or full $arImage = wp_get_attachment_image_src($iImageID,'large'); $iImageWidth = $arImage[1]; $iImageHeight = $arImage[2]; ?> <img src="<?php echo $metaurl; ?>" height="<?php echo $iImageHeight; ?>" width="<?php echo $iImageWidth; ?>" /> </code> – okidoki232 May 29 '10 at 2:21
add comment
enter at least 15 characters