Display images in posts

This topic contains 5 reply and 2 voices, and was last updated by hatchmedia 11 years ago
Viewing 5 Posts - 1 through 5 (of 5 total)
Author Posts
April 22, 2013 at 7:52 pm 2729
hatchmedia Hi guys, Hopefully an easy one.  I am just looking to display my images on my posts.  I am currently displaying the Feature Image using the code: `ID )): ?> ID ), 'full' ); ?> ` in my single.php. I have tried adding:
<?php
$images = get_post_meta( $post->ID, 'mey_key_name' );
if ($images) {
    foreach ($images as $attachment_id) {
        $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
        $full_size = wp_get_attachment_url( $attachment_id );
        printf( '<a href="%s">%s</a>', $full_size, $thumb );
    }
}
?>
...as per the help documents but to no avail.
I hope you can help!
Damien
April 22, 2013 at 8:17 pm 2732
Tareq Hasan Tareq Hasan

The code is working fine, just tested. May be you missed something, check again 🙂

April 22, 2013 at 8:19 pm 2734
hatchmedia hatchmedia

Should I be replacing the Featured Image code or adding to it? 🙂

….because I have tried both ways now and cant seem to get it working for some reason!

April 22, 2013 at 8:45 pm 2738
hatchmedia hatchmedia

Oh Tareq!

I am being stupid!  I never changed the name of my ID to what my custom fields are called.  Simple simple mistake but hopefully it might help people in the future!

Damien

 

April 22, 2013 at 8:58 pm 2741
Tareq Hasan Tareq Hasan

That code is for showing the images from a custom field. Are you using any custom field for the images? Otherwise that won’t work.

April 22, 2013 at 9:01 pm 2742
hatchmedia hatchmedia

Hey Tareq,

All ok now, I had just not included the custom field ID.  Its working now for me!

Thanks again!

Viewing 5 Posts - 1 through 5 (of 5 total)