• Resolved artflutter

    (@artflutter)


    Hi, I have a page called “Front Page” with a page id of 22. I added a single image to it and in the media library it has an id of 30.

    in my page template I want to insert this image and can do so with the code

    <?php echo wp_get_attachment_image( '30', 'full' ); ?>

    My question is, how do I, from within the loop get the ID of the gallery image associated with the post?

    Regards, Alex.

Viewing 1 replies (of 1 total)
  • Thread Starter artflutter

    (@artflutter)

    Figured it out in the end. For reference code used is below.

    <?php
    $attargs = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID);
    
    $attachments = get_children($attargs);
    if ($attachments) {
    	foreach ($attachments as $post) {
    		?>
    		<img src="<?php echo wp_get_attachment_url($post->ID); ?>" alt="<?php the_excerpt(); ?>" title="<?php the_title(); ?>" class="staff-img" />
    		<?php
    		break; //only display first image
    	}
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘add image gallery in page template.’ is closed to new replies.