How to add an image to a theme page template in code?
Haven’t tested this, but the key is to use get_posts() with the proper arguments so as to retrieve the ids of the attachments, e.g. $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment … Read more