Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve been strugling with that, too. Have succeeded couple of times by adding pics and updating web page pic after pic and the last one seems to go first. And you have to import each pic when adding. Choosing from media library tends to use old order.

    It′s an old thread but i actually had to make some changes to code to achieve this, so i′ll share for future googlers.

    With this solution images will be ordered in the order they appear in shortcode

    SOLUTION
    Search in folder wp-content/responsive-media-gallery/responsive-media-gallery.php

    In there you will find a function called “igr_gallery_shortcode”.

    1)Add ‘custom_order’ => false, to array passed to extract, around line 132.

    2) We add an if clause for using our custom order

    if( $custom_order ){
    			foreach( explode("," , $ids)  as $id_img  )
    			{
    				$attachments[$id_img] = $_attachments[$id_img];
    			}	
    
    		}else{
    
    			foreach ( $_attachments as $key => $val )
    			{
    				$attachments[$val->ID] = $_attachments[$key];
    			}
    
    		}

    You will end up with something like this:

    function igr_gallery_shortcode($attr)
    {
    	global $post;
    	$options = get_option('igr_options');
    
    	if (isset($attr['orderby']))
    	{
    		$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    		if ( !$attr['orderby'] )
    			unset( $attr['orderby'] );
    	}
    
    	extract(shortcode_atts(array(
    		'orderby'		=> 'menu_order ASC, ID ASC',
    		'id'			=> $post->ID,
    		'itemtag'		=> 'dl',
    		'icontag'		=> 'dt',
    		'captiontag'	=> 'dd',
    		'columns'		=> 3,
    		'size'			=> 'thumbnail',
    		'include'		=> '',
    		'ids'			=> '',
    		'custom_order'	        => false //parameter added
    	), $attr));
    
        $count = 1;
    	$id = intval($id);
    
    	if(!empty($ids))
    	{
    		$ids = preg_replace( '/[^0-9,]+/', '', $ids );
    		$_attachments = get_posts( array(
    										'include'			=> $ids,
    										'post_type'			=> 'attachment',
    										'post_mime_type'	=> 'image',
    										'orderby'			=> $orderby
    										)
    								  );
    		$attachments = array();
    
                 //Select if we want to order images like its declared in shortcode
    
    		if( $custom_order ){
    			foreach( explode("," , $ids)  as $id_img  )
    			{
    				$attachments[$id_img] = $_attachments[$id_img];
    			}	
    
    		}else{
    
    			foreach ( $_attachments as $key => $val )
    			{
    				$attachments[$val->ID] = $_attachments[$key];
    			}
    
    		}
    
    //thats all the rest of the function remains the same

    Now you can use shortcode in this way:

    [gallery ids="576,579,571,572,573,574,578,575,577,580" orderby="none" custom_order="true"]'
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unable to change image order’ is closed to new replies.