Pull all post/page images for slider?
-
Hi Everyone!
I have been looking high and low for a solution, and have actually found a few posts on the matter. However, none of the solutions seem to be working for me—although I do think that they have gotten me close.
The problem
I am building a template(s) that should pull all the media (images and video—but maybe let’s just start with images ?? associated with the current post/page and output them as list items in an- for use in flexslider. This is what I have:
function add_flexslider() { // display attachment images as a flexslider gallery $attachments = get_children(array('post_parent' => get_the_ID(), 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_mime_type' => 'image','caption' => $attachment->post_excerpt, )); if ($attachments) { // see if there are images attached to posting ?> <!-- Begin Slider --> <div class="flexslider"> <ul class="slides"> <?php // create the list items for images foreach ( $attachments as $attachment_id => $attachment ) { echo '<li>'; echo wp_get_attachment_image($attachment_id, 'large'); echo '</li>'; } ?> </ul> </div> <!-- End Slider --> <?php } // end see if images } // end add flexslider
Then I bring in the function like so: <?php add_flexslider(); ?>
So far this is not returning any results. I was playing around with different variations previously, and removing “post_parent’ => get_the_ID()” got it working, but it brought in ALL my images in a carousel so crazy it would make your head spin!
Additional Concerns
I am using this code for a dev. site, so all of the post/page images are actually hyperlinks to the live site. Should this make a difference? Also, all images were inserted/published right through the WordPress WYSIWYG editor, no galleries, fancy plugins, or anything else.Thanks in advance for your consideration! Y’all are the best!
- The topic ‘Pull all post/page images for slider?’ is closed to new replies.