Forums

List all photos in post (11 posts)

  1. sshilo
    Member
    Posted 1 year ago #

    Does anyone know how to create a "loop" of all photos in a post?

    Thanks :)

  2. Reuben Gunday
    Member
    Posted 1 year ago #

  3. pavy
    Member
    Posted 1 year ago #

    You could use a plugin for this, which is much simpler:
    - http://wordpress.org/extend/plugins/get-the-image/

  4. sshilo
    Member
    Posted 1 year ago #

    reuben,

    (my post has 2 images)

    When I use that code within the loop on my single.php, I get 4 images that have nothing to do with this post.

    Any ideas?

    pavvy,
    I am not sure that plugin returns an array of the images

  5. Reuben Gunday
    Member
    Posted 1 year ago #

    If you have something like this, you'll get all the images
    $images =& get_children( 'post_type=attachment&post_mime_type=image' );
    add post_parent parameter

  6. sshilo
    Member
    Posted 1 year ago #

    yup, I just figured that out (didn't have the id). Now, I'm trying to get it to give me just the url, rather than printing it to the screen. I have:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_ID() );
    
    if ( empty($images) ) {
    	// no attachments here
    } else {
    	foreach ( $images as $attachment_id => $attachment ) {
    		echo wp_get_attachment_link($attachment_id, $size = 'thumbnail', $permalink = true, $icon = false);
    	}
    }

    but it's still adding the image tag to the page, rather than echoing the url

  7. Reuben Gunday
    Member
    Posted 1 year ago #

    Change this
    echo wp_get_attachment_link($attachment_id, $size = 'thumbnail', $permalink = false, $icon = false);
    to

    echo wp_get_attachment_link($attachment_id, 'thumbnail', false, false);

    and clear the cache then test the page.

  8. sshilo
    Member
    Posted 1 year ago #

    when I do that, it actually still "prints" the thumbnails to the screen.

    I cleared the cache, did a forced refresh and no luck. I now have this:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_ID() );
    
    if ( empty($images) ) {
    	// no attachments here
    } else {
    	foreach ( $images as $attachment_id => $attachment ) {
    		echo wp_get_attachment_link($attachment_id, 'thumbnail', false, false);
    	}
    }
  9. sshilo
    Member
    Posted 1 year ago #

    got it to work with this (I know it's not elegant):

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

    if ( empty($images) ) {
    // no attachments here
    } else {
    foreach ( $images as $attachment_id => $attachment ) {
    $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
    echo $image[0];
    }
    }

  10. Reuben Gunday
    Member
    Posted 1 year ago #

    hmm....site url??

  11. sshilo
    Member
    Posted 1 year ago #

    unfortunately, I can't show you the site, but it's a theme I'm working with and it's using the theme test plugin, so you can't see it without being logged it.

    thank you very much for the help

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.