• The get_children code sample below returns an array of the images attached to a post:

    $images =& get_children( 'post_type=attachment&post_mime_type=image' );

    What I’d like to do is get the thumbnails of whatever photos are returned, using the dimensions set in Settings => Miscellaneous => Thumbnail size. Is there a clear way to do this? A function I can apply to the returned values?

Viewing 5 replies - 16 through 20 (of 20 total)
  • This is great, almost exactly what I was looking for.

    Is it possible to manipulate mintimperials 2nd method, so that instead of just returning the first thumbnail, it excludes it, showing only the 2nd, 3rd, 4th etc?

    Thanks

    Tim

    Hello,

    Still trying to figure this out.

    I tried changing "<img src=\"{$firstImageSrc[0]}\" />"; ?>
    to
    "<img src=\"{$firstImageSrc[1]}\" />"; ?> which to me should pull the next entry out of the array.

    Obviously I don’t understand arrays enough. Any help?

    Tim

    Hello everyone,

    please help me with the error I get (similar to other posters’).

    I pasted mintimperial‘s code into my page.php, right after the beginning of posts loop:

    if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php $images =&amp; get_children( 'post_type=attachment&amp;post_mime_type=image&amp;post_parent=' . $post->ID );
    $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images)));
    echo "<img src=\"{$firstImageSrc[0]}\" width=\"32\" height=\"32\" />"; ?>

    I get 2 errors:

    Warning: array_keys(): The first argument should be an array in /home/www/mywebsite.com/wp-content/themes/basic2col/page.php on line 11

    Warning: array_shift(): The argument should be an array in /home/www/mywebsite.com/wp-content/themes/basic2col/page.php on line 11

    Line 11 being
    $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images)));

    Is this because $images is actually empty?
    And then is &images empty because it searches for pics in posts on the current page (and current page is empty, has no posts)?

    If correct, then how do I make it search through all posts in the blog, not only on the current page?

    Thanks for support.

    A quick update:

    I tested the same code on index.php
    It displays those 2 error messages right after each post’s excerpt.

    What am I doing wrong?

    Thank you for help.

    Just tried to
    print "images[0] is $images[0] !";

    and it prints “images [0] is !”
    So, $images is empty, I suppose.

    I don’t know how get_children and all the other stuff involved here works, so I can’t understand why is nothing written in $images.

    Could you explain it a little?

    Thanks.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Getting thumbnails of images attached to a post?’ is closed to new replies.