[wp-hackers] Always finding more and more cleverness in WP...
Frank Bueltge
frank at bueltge.de
Sat Mar 28 09:49:11 GMT 2009
the first image of content as thumbnail:
<?php fb_TeaserPics($post->ID, 'thumbnail'); ?>
i use this function in a theme for more option; you can write very smaller,
a you have so the functions for read the images on the post
function fb_getTeaserPics($postID, $what) {
global $wpdb;
$postID = (int) $postID;
$attachments =
get_children("post_parent=$postID&post_type=attachment&post_mime_type=image&limit=1");
if ($attachments && $what != 'src' ) {
foreach ($attachments as $bild) {
$html = '';
$image = wp_get_attachment_image_src($bild->ID, $what);
if ( $image ) {
list($src, $width, $height) = $image;
if ( is_array($size) )
$size = join('x', $size);
$html = '<img src="' . attribute_escape($src) . '" width="'.
$width .'" height="' . $height .'" class="alignleft ' . $what . '
attachment-'.attribute_escape($size).'" alt=""/>';
}
}
} elseif ($attachments && $what == 'src' ) {
foreach ($attachments as $bild) {
$html = '';
$image = wp_get_attachment_image_src($bild->ID, $what);
if ( $image ) {
list($src, $width, $height) = $image;
if ( is_array($size) )
$size = join('x', $size);
$html = attribute_escape($src);
}
}
}
return $html;
}
function fb_TeaserPics($postID, $what) {
echo fb_getTeaserPics($postID, $what);
}
Liebe Grüsse
Frank
__
Das Buch: WordPress - Weblogs einrichten und administrieren, Open Source
Press
ISBN 978-3-937514-33-8
http://wordpress-buch.bueltge.de/das-buch/
http://bueltge.de : frank at bueltge.de
http://wpengineer.com : frank at wpengineer.com
__
Frank Bültge
Tel: +49 3691 212951
Mobil: +49 170 5322053
E-Mail: f.bueltge at inpsyde.com
Inpsyde GmbH
Mutzer Heide 3
51467 Bergisch Gladbach
Steuernummer: DE 249 552 518
Geschäftsführer: H. Rohé
http://inpsyde.com
http://pressthis.de
On Sat, Mar 28, 2009 at 3:52 AM, Jan Bucher <janbucher at gmail.com> wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list