Hi
I am using Wordpress and and looping through posts of a particular type, but wish to show a different image for each post from a list of images uploaded to the media library
Here's what I am doing
How do I get a get the images out of my array, one for each post in the loop? If there are more posts than images, we start back at the first etc
Thanks
I am using Wordpress and and looping through posts of a particular type, but wish to show a different image for each post from a list of images uploaded to the media library
Here's what I am doing
PHP:
//create my array of images with a particular title (such as myimages, myimages1, myimages823746782)
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
's' => 'myimages',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image ) {
$images[] = wp_get_attachment_url( $image->ID );
}
//then loop through my posts
$latestjobs = $wpdb->get_results("SELECT ...");
foreach ( $latestjobs as $latestjob )
{
echo '<div>';
echo '<h2>'.$latestjob->post_title.'</h2>';
echo '<img src='..' />'; //this is where I want each to show a different image from my array, how do I do that?
echo '</div>';
}
How do I get a get the images out of my array, one for each post in the loop? If there are more posts than images, we start back at the first etc
Thanks