[wp-hackers] Always finding more and more cleverness in WP...

Jan Bucher janbucher at gmail.com
Sat Mar 28 02:52:20 GMT 2009


Hey,

(you may read the replied-to-mail first, been a while)

bookmarked it a while ago ;) Now i tried to use it and its not
working. The reason, as far as i can see, is that you need to put the
ID of the attachment and not the ID of the post into the
function-call. So it is not as handy as it seemed first.

Its 4 o'clock in the morning (down here in Germany). I don't see it:
How can I retrieve the ID of the first attached Picture of a post? I
mean: Is there any easy WP-Way or do i have to parse the content?

Kind regards
Jan

On Tue, Aug 19, 2008 at 7:57 PM, Otto <otto at ottodestruct.com> wrote:
> I was making an image.php template for a site, so naturally I'm using
> wp_get_attachment_image to get the IMG link for the page. However, I
> needed to have it constrain the image size to a certain size.
>
> Looking at the definition for it, I see this:
> function wp_get_attachment_image($attachment_id, $size='thumbnail',
> $icon = false)
>
> Dang. I didn't want to use one of the predefined sizes in the
> Settings->Miscellaneous screen, so I started sifting through the code.
> Lo and behold, I find this buried down in image_get_intermediate_size:
>
> function image_get_intermediate_size($post_id, $size='thumbnail') {
> ...
>        // get the best one for a specified set of dimensions
>        if ( is_array($size) && !empty($imagedata['sizes']) ) {
>
> Huh? The $size can be an array? Neat!
>
> Reading the code, it actually takes an array of max sizes you want on
> each dimension, finds the next biggest one, then eventually returns
> the image tag with the sizes you specify (proportionally scaled
> correctly, of course). This lets the browser do the grunt work of
> scaling the image down to fit. Okay, so browser scaling sucks, it's
> still semi-okay at scaling down than up. And newer browsers (FF3) use
> good routines to do this anyway.
>
> In short:
> <?php echo wp_get_attachment_image( $post->ID, array(600,600) ); ?>
> Gives me an IMG tag that has a max size of 600 on one side, using the
> next biggest scaled image it has as per the parameters on the
> Settings->Miscellaneous screen.
>
> I just found that highly clever and thought everybody should know about it. :)
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Jan Bucher
e: janbucher at web.de
m: 0176 / 2444 7149
w: www.radioaktiv.org


More information about the wp-hackers mailing list