WordPress.org

Forums

more tag with gallery images (1 post)

  1. alpual
    Member
    Posted 1 year ago #

    I'm still a bit new to WordPress, and to php, so this might be really simple, but here goes:
    I'm trying to make my default index.php page display an image from a gallery, instead of a "Read More..." link in place of the <!--more--> tag. I want it to look at each post (all posts contain a gallery) and pick the first image from the post to use. Here is the code I'm using, inside The Loop,
    `<?php
    $gallery=get_post_gallery_images( the_ID() );
    $image_attributes = wp_get_attachment_image_src( $gallery[0] );
    the_content('<img src="'.$image_attributes[0].'" width="300" height="211" />');
    ?>`
    From what I read about get_post_gallery_images it should return an array of the images in the gallery found on the page which is referenced by the_ID(). I'm trying to get the url of the first image in the gallery, and from what I understand about wp_get_attachment_image_src, it should give me the url from the image id.

    When I use this code it displays an image, so I know it can be done if I can get the URL:

    <?php
    the_content('<img class="alignleft size-medium " alt="Memories Portfolio" src="http://www.caitlinsabo.com/wp-content/uploads/2013/10/home-page-1-300x211.jpg" width="300" height="211" />');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic