Support » Plugins » List all images attached to a post based on gallery

  • I hade some serious issues trying to create a gallery based on the built in gallery-order in the post. So I have to share this so that more people will find out about it.

    First, this is what you should put in the functions.php. This is based on another function called attachment_toolbox but with a slight modification.

    function display_images_in_list($size = thumbnail) {
    
    	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;
    
    		}
    	}
    }

    This function lines up every image that is attached to the post AND sorts them as the gallery is.

    The original code contained get_children() which is very limited in options so I found that get_posts does the same thing, but can use the same parameters as query_posts.

    'orderby'        => 'menu_order',
    'order'           => 'ASC',

    Are the important ones which sorts the images after the gallery.

    Then just put this code in single.php (haven’t tried with pages).
    <?php display_images_in_list('large'); ?>

    The large is the size of the images. You can use small, medium, large (or more?).

    Then you can just use a jquery, flash, whatever to create the gallery from those options. I used jquery.cycle.

    I searched for at least a week until I figured this out on my own.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List all images attached to a post based on gallery’ is closed to new replies.