WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Get_posts attachments showing all images in media library not just page

[Resolved] Get_posts attachments showing all images in media library not just page

  • Hi,

    I’m trying to display all images in a page’s gallery on the page so I can use JQuery Cycle to make a slideshow. I can make the images and slideshow work except that it is displaying all the images in the media library, not just those on the page…

    I’ve got this in my functions.php

    function display_images_in_list($size = full) {
    
    	if($images = get_posts(array(
    		'post_parent'    => get_the_ID(),
    		'post_type'      => 'attachment',
    		'numberposts'    => -1, // show all
    		'post_status'    => null,
    		'post_mime_type' => 'image',
                    'orderby'        => 'menu_order',
                    'order'           => 'ASC',
    	))) {
    		foreach($images as $image) {
    			$attimg   = wp_get_attachment_image($image->ID,$size);
    
    echo $attimg;
    
    		}
    	}
    }

    and then in the single.php (within the loop)

    <div class="slideshow-images">
    <?php display_images_in_list('full'); ?>
    </div>

    Can anyone help?

Viewing 1 replies (of 1 total)
  • I’ve got this sorted from another forum – I needed to change the:

    'post-parent' => get_the_ID()

    to

    'post-parent' => get_queried_object_id()

    et voila, just the pages images!

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Get_posts attachments showing all images in media library not just page’ is closed to new replies.
Skip to toolbar