Pulling images from posts
-
Greetings all…..
I’d like a bit of advice from you lovely people, if I may. I’m trying to pull the images from each individual post, display them as a thumbnail, and use that thumbnail as a link to the post the image was pulled from. I’ve had a look at this thread http://wordpress.org/support/topic/140609?replies=48 and that’s been useful, but it’s marked as resolved, hence this new thread.
Here’s the code I’m using
<?php if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', ))) : ?> <ul class="post_list"> <?php foreach( $images as $image ) : ?> <li><?php echo wp_get_attachment_link($image->ID); ?></li> <?php endforeach; ?> </ul> <?php else: // No images ?> <!-- This post has no attached images --> <?php endif; ?>
All well and good. It pulls the images from the posts, and they become links to the image itself. Being a bit of PHP n00b, what I don’t get is:
a)what is creating the link to the image
b)how can I make that link a link to the post instead of to the image.
Is that possible to do?
Am I asking too much of WordPress?Hope someone can give me some advice to save my skull caving in from hitting it against the wall.
Cheers
🙂
- The topic ‘Pulling images from posts’ is closed to new replies.