WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get_posts attachments showing all images in media library not just page (2 posts)

  1. charleymediumrare
    Member
    Posted 2 years ago #

    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?

  2. charleymediumrare
    Member
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.