WordPress.org

Forums

[resolved] Get an image with a given title from post's gallery (2 posts)

  1. wickethewok
    Member
    Posted 5 years ago #

    On my individual posts' pages I want to have different images outside of the posts' content. To do this, I figured I would have admins upload different image files with the title "banner" to each post's gallery. How can I can retrieve and display this image in single.php?

    Note that I am already using the WordPress post thumbnail feature for an actual thumbnail for each post, otherwise I would use that.

  2. wickethewok
    Member
    Posted 5 years ago #

    I think I finally figured it out...

    have_posts();
    the_post();
    $images =& get_children(array('post_mime_type' => 'image', 'post_parent' => get_the_ID()));
    rewind_posts();
    
    $image_url = null;
    foreach($images as $image) {
    	if($image->post_title == 'banner') {
    		$image_url = $image->guid;
    		break;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags