• Resolved bigskydj09

    (@bigskydj09)


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bigskydj09

    (@bigskydj09)

    It turns out the images HAVE TO BE ATTACHED…which is to say, they cannot be hyperlinked. Other than that, the code is sound.

    Can you elaborate a little on what you mean by ATTACHED and not hyperlinked? I’m trying to achieve the same thing here, using slightly different code:

    <div class="flexslider">
    <ul class="slides">
    	<?php
    	$attachments = get_attached_media( 'image', 36 );
    	foreach($attachments as $attachment) {
    	    $img = wp_get_attachment_image_src($attachment->ID, 'medium');
    	    if($img !== false) {
    	?>
    	<li><img src="<?php echo $img[0]; ?>" /></li>
    	<?php
    	    }
    	}
    	?>
    </ul>
    </div>

    However, the images do not show up in the browser, although they DO show up in the source code, strangely. I am testing locally, using MAMP, and that could present an issue on why they’re not showing up.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pull all post/page images for slider?’ is closed to new replies.