• Resolved bcreighton

    (@bcreighton)


    Hi,

    Is there get attachment function that would allow me grab the latest attachment during the loop?

Viewing 3 replies - 46 through 48 (of 48 total)
  • Hi,
    I’m a bit of a WP/PHP newbie. This post has been really helpful, but I’m a bit confused. I need to pull the images from each post individually, but instead of them linking to the actual image itself, I need the image to link to the post that its been pulled from. I’ve been using this bit of code.

    <?php
    
    	   $args = array(
    	   	'post_type' => 'attachment',
    	   	'numberposts' => -1,
    	   	'post_status' => null,
    	   	'post_parent' => $post->ID
    	   	);
    
    	   $attachments = get_posts($args);
    	   if ($attachments) {
    	   	foreach ($attachments as $attachment) {
    	   		echo apply_filters('the_title', $attachment->post_title);
    	   		the_attachment_link($attachment->ID, false);
    	   	}
    	   }
    
    	   ?>

    I guess I can use <?php the_ID(); ?> to link to the post, but don’t know where it needs to go, or in fact what is generating the link to the image in the first place.

    Can anyone help?
    Have I made any sense?

    Cheers
    ??

    I’m wanting to display a couple of random thumbnails from a specific category, with the thumbs linking to the post they are from. Pretty much like Matt does for his Serendipity.

    I’m trying out some of the code from this, but I’m needing random instead of latest.

    Any help?

    Thanks

    Should I do a new topic since this one is marked resolved?

    Thanks in advance!

Viewing 3 replies - 46 through 48 (of 48 total)
  • The topic ‘Pull latest attachment from post?’ is closed to new replies.