I want to have the ability to use pictures from the media library in a jquery slider on the home page so that it's easy for someone else to update the pictures without having to hardcode it. I have attached a bunch of photos to a post and tried this
<?php
$image_query = new WP_Query(array('name'=>'slider-images'));
while ( $image_query->have_posts() ) : $image_query->the_post();
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo '<img src="'.wp_get_attachment_url($attachment->ID).'" />';
echo '</li>';
}
}
endwhile;
wp_reset_postdata();
?>
but it doesn't display anything. Is there something wrong with my code or is there an easier/better way to group images together rather than put them in a post?
EDIT: If I use the_content() in my $image_query loop it outputs the images like
<p>
<a href="...">
<img src="..." />
</a>
</p>
but what I need is something like
<li>
<a href="...">
<img src="..." />
</a>
</li>
wp_get_attachment_url