Split Categories Alphabetically Index

Forums › Forums › Search & Filter Pro › Split Categories Alphabetically Index

Viewing 3 posts – 1 through 3 (of 3 total)
  • Anonymous
    #53739

    Hi, this plugin is awesome!

    I couldn’t find an answer in this forum and as I am not a PHP expert maybe you could solve this for me.

    I am showing a list of my categories like so:

    I would like to index those categories into alphabetical sections like this:

    I found this plugin that does what I want but don’t know how to integrate it to S&F.

    Any help would be much appreciated!

    Thanking you in advance,

    Kostas

    Anonymous
    #53742

    So I actually figured out a way to do that:

    In case anyone has this same question/problem just add this code:

    <script>
    var list = { letters: [] };
    jQuery(".sf-field-category > ul").children("li").each(function(){
      var itmLetter = jQuery(this).text().substring(0,1).toUpperCase();
      if (!(itmLetter in list)) {
        list[itmLetter] = [];
        list.letters.push(itmLetter);
      }
      list[itmLetter].push(jQuery(this));
    });
    list.letters.sort();
    jQuery(".sf-field-category > ul").empty();
    jQuery.each(list.letters, function(i, letter){
      list[letter].sort(function(a, b) {
        return jQuery(a).text().toUpperCase().localeCompare(jQuery(b).text().toUpperCase());
      });
      var ul = jQuery("<ul/>");
      jQuery.each(list[letter], function(idx, itm){
        ul.append(itm);
      });
      jQuery(".sf-field-category > ul").append(jQuery("<li/>").append(jQuery("<label/>").attr("name", letter.toLowerCase()).addClass("title").html(letter)).append(ul));
    });
    </script>
    Trevor
    #53767

    Thanks for sharing. I have tidied up the posts for you 😉

Viewing 3 posts – 1 through 3 (of 3 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.