• Resolved Anonymous User 9105421

    (@anonymized-9105421)


    I’m looking for help to change the sort-order displayed in the dropdown menus that are shown on the NextGen Gallery “Add Gallery / Images” page and while adding images to a post via “Add Media > NextGen Gallery”. Both these dropdowns are sorted by gallery ID, i want to have them sorted ascending alphabetically by gallery title which would make my life a lot easier to locate and select the wanted gallery from the list.

    Does anyone has an idea how to go about this? I’m using NextGEN Gallery 2.2.33 on WordPress 4.9.1.

    The code of the dropdown shown on the “Add Gallery / Images” (nextgen-gallery\products\photocrati_nextgen\modules\nextgen_addgallery_page\templates\upload_images.php) page looks like this:

    <div id="gallery_selection">
        <label for="gallery_id">Gallery</label>
        <select id="gallery_id">
            <option value="0">Create a new gallery</option>
            <?php foreach ($galleries as $gallery): ?>
                <option value="<?php echo esc_attr($gallery->{$gallery->id_field}) ?>"><?php echo esc_attr($gallery->title) ?></option>
            <?php endforeach ?>
        </select>
        <input type="text" id="gallery_name" name="gallery_name"/>
    </div>

    I know it should be possible to have both these dropdowns sorted ascending alphabetically by gallery title as i once worked with an older version of NextGen Gallery that someone edited to do just that.

    Thanks in advance for any advice on how to go about this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Anonymous User 9105421

    (@anonymized-9105421)

    OK… thought i found a solution but that proved not working 100% so i removed it to prevent confusion.

    Plugin Contributor Imagely

    (@imagely)

    @damsko – Have you considered the following hooks:

    /** Adjust Manage Galleries list results */
    /** see ..wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/admin/manage-galleries.php */
    
    add_filter( 'ngg_manage_galleries_items_per_page', ‘callback_function_return_int’ );
    add_filter( 'ngg_manage_galleries_items_order', ‘callback_function_return_string’ );
    add_filter( 'ngg_manage_galleries_items_orderby', ‘callback_function_return_int’ );

    – Cais.

    Thread Starter Anonymous User 9105421

    (@anonymized-9105421)

    Thanks Imagely but that does not solve my issue, i now see that the same issue was already mentioned before in this thread: https://www.ads-software.com/support/topic/gallery-sort-order-adding-gallerie-picture/

    I found an alternative way to get my desired alphabetically sorted drop-down lists when adding images to posts and when selecting galleries to upload images to, as i have so many galleries it greatly improves my workflow to have the dropdowns sorted alphabetically instead of by gallery ID.

    What i did was switch to “NextCellent Gallery – NextGEN Legacy” (https://www.ads-software.com/plugins/nextcellent-gallery-nextgen-legacy/) which basicaly is a continuation of the NextGEN Gallery version 1.9.13 code. I got current version 1.9.35 running without problems on PHP 7.0.26. It also found all my excisting NextGEN Gallery galleries.

    To get the alphabetically sorted drop-downs i made following edits:

    in admin/class-ngg-adder.php:

    line 133 from:
    			'galleries' => $nggdb->find_all_galleries('gid', 'DESC'),
    ----------- to -------------------->
    			'galleries' => $nggdb->find_all_galleries('title', 'ASC'),
    
    and line 579 from: (leave this unchanged when you want to keep the display of the gallery ID ("123 - Gallery Name"))
    				echo '<option value="' . $gallery->gid . '" >' . $gallery->gid . ' - ' . esc_attr( $name ) . '</option>';
    ----------- to -------------------->
    				echo '<option value="' . $gallery->gid . '" >' . esc_attr( $name ) . '</option>';

    in admin/media-upload.php:

    line 170 from:
    			$gallerylist = $nggdb->find_all_galleries();
    ----------- to -------------------->
    			$gallerylist = $nggdb->find_all_galleries('title', 'ASC');

    A final edit i made when after a image upload the “Edit gallery” link was not displayed, to get that fixed for me i edited:

    in admin/functions.php:

    line 298 from:
    		//TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX
    		$message  = $created_msg;
    		if ( count($updated) > 0)
    			$message .= $c . __(' picture(s) successfully renamed','nggallery') . '<br />';
    		if ( count($image_ids) > 0 )
    			$message .= count($image_ids) .__(' picture(s) successfully added','nggallery') . '<br />';
    		if ($created_msg) {
    		$message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage&mode=image&gid=' . $gallery_id . '" >';
    		$message .=  __('Edit gallery','nggallery');
    		$message .= '</a>]';
    		}
    		if (!$message)
    		$message  = __('No images were added.','nggallery');
    
    		nggGallery::show_message($message);
    
    ----------- to -------------------->>>>
    
    		//TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX
    		$message  = $created_msg . count($image_ids) .__(' picture(s) successfully added','nggallery');
    		$message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage&mode=image&gid=' . $gallery_id . '" >';
    		$message .=  __('Edit gallery','nggallery');
    		$message .= '</a>]';
    		
    		nggGallery::show_message($message); 

    Of course not a perfect approach as the edits will be lost when the plugin gets updated, then you will have to see if the edits still will work and can be repeated. So not pretty but it makes my workflow so much easier that for me its worthwhile.

    Note on running “NextCellent Gallery – NextGEN Legacy” alongside “NextGEN Gallery”:
    https://www.ads-software.com/plugins/nextcellent-gallery-nextgen-legacy/#installation
    Remember: plugin won’t activate if NextGEN is installed and activated. A message will remind you this situation. Please deactivate any NextGEN plugin before installing NextCellent.

    Be save when experimenting, back up your database and galleries first.

    Plugin Contributor Imagely

    (@imagely)

    @damsko – Thanks for sharing!

    – Cais.

    Thread Starter Anonymous User 9105421

    (@anonymized-9105421)

    Thanks Imagely for looking into the issue. It would be a great feature to have a option on how to sort the dropdown menus that are used when uploading images and adding images to posts.

    I currently have 915 galleries and they are all sorted per category like “trousers”, “shoes”, “bottles”, “t-shirts”, “flowers”, “cars”, “beans”, etc., etc…

    So when i want to add a new image to an excisting gallery like by example the gallery “cars” then with the default sorting by gallery ID i will have to go over the entire drop-down with 915 entries to look for “cars”, when the list is alphabetic i can straight go to “c” section holding “cars”. Same goes with posting, when i now want to add an image from the “cars” gallery i again have to go over the 915 entries trying to spot “cars”.

    In some scenarios it might be easy to have list sorted by ID so that its easier to access/find the last gallery added but when you have your galleries set up similar to mine then the alphabetical sort makes more sense.

    Plugin Contributor Imagely

    (@imagely)

    @damsko – Feel free to share your thoughts and ideas on this as a Feature Request here: https://imagely.com/feature-voting/

    Thanks!

    – Cais.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Gallery sorting order dropdown menus “Add Gallery / Images” and “Add Media”’ is closed to new replies.