Hey @xzackly!
Thanks for posting about this!
The following Javascript should do the trick:
var list, i, switching, b, shouldSwitch;
list = document.getElementsByClassName("options");
switching = true;
while (switching) {
switching = false;
b = list[0].getElementsByClassName("opt");
for (i = 0; i < (b.length - 1); i++) {
shouldSwitch = false;
if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) {
shouldSwitch= true;
break;
}
}
if (shouldSwitch) {
b[i].parentNode.insertBefore(b[i + 1], b[i]);
switching = true;
}
}
Please add it to a custom frontend .js file, which is called on your gallery page. You can also add it to /photo-gallery/js/bwg.js file, but the changes will clear out in case you update the plugin.
Let us know if this helps.
Cheers!
Awesome! Thanks.
I will attempt to do as you say but if you (or anyone else) has a moment to explain how to call a frontend .js file, that will save me a lot of googling. I’m not afraid of code but I also don’t code.
I think what you’re saying is that I need to add some code to standbyformindcontrol.com/i-like-to-watch/ that calls a new file i’d create that includes the above code. I bet I can make that work through trial and error.
But thanks. I bet something like this would be a reasonable addition to future builds.
okay. reporting on SOME success in case others want to try the same thing.
your code works but only BEFORE one uses the tag list to sort the images. once the sort function is applied, the list order reverts to an unsorted list.
here’s what I’ve done (with much help from a friend at PiP Coders)
I added:
/**
* Implement the custom sort for gallery search
*/
function gallery_sort_search_enqueue() {
if ( is_page( 'i-like-to-watch' ) ) {
wp_enqueue_script( 'gallery_sort_search', get_template_directory_uri() . '/js/gallery_sort_search.js');
}
}
add_action( 'wp_enqueue_scripts', 'gallery_sort_search_enqueue' );
to the end of the functions.php file of the theme I’m using (a modified version of Oxygen).
then I uploaded your code in a file called gallery_sort_search.js in my theme’s js/ folder.
so you can see that the tags sort alphabetically here: http://www.standbyformindcontrol.com/i-like-to-watch/
but if you use the sort function, no love.
if you have any additions/edits to your code that will carry over once the sort function is applied, that would be tidy.
Hey @xzackly!
In that case, could you please contact our team directly through this form? Our development team will make the ordering alphabetized, so that it will permanently appear that way.
Make sure to indicate the link to this forum thread in your message.
Thanks! Have a great day!