We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22797
    • 134 Posts
    It would be nice to have a library-style/natural language alphabetization in the document tree, ignoring punctuation (quotation marks, for example), and words such as "The," "A," "An," and so on. Accomplishing this is relatively easy, using a conditional query in MySQL. I modified the default sort order in manager/frames/nodes.php file in 0.9.6.2 on line 77 to say this:
    $_SESSION['tree_sortby'] = 'isfolder DESC, menuindex ASC, 
    CASE 
    WHEN substring(pagetitle from 1 for 2) = "A " THEN substring(pagetitle from 3) 
    WHEN substring(pagetitle from 1 for 3) = "An " THEN substring(pagetitle from 4) 
    WHEN substring(pagetitle from 1 for 4) = "The " THEN substring(pagetitle from 5) 
    WHEN substring(pagetitle from 1 for 7) = "“" THEN substring(pagetitle from 8) 
    WHEN substring(pagetitle from 1 for 1) = '."'\"'".' THEN substring(pagetitle from 2)  
    WHEN substring(pagetitle from 1 for 1) = "'."'".'" THEN substring(pagetitle from 2) 
    ELSE pagetitle 
    END';

    Similar changes would need to be made for instances in which a user changes the sort order using the drop down option at the top of the tree.

    The thing that complicates this, though, is that these are language-specific rules. Probably the best way to handle it would be to create another variable in the includes/lang files that creates an array of words and/or characters to ignore in the sorting, plus the number of characters that is necessary to skip for those characters. Something like this:
    $_lang["natural_sort"] = array(
    "A " => 2, 
    "An " => 3, 
    "The " => 4, 
    "“" => 7,
    "'" => 1,
    '"' => 1
    )

    Or the array could be constructed slightly differently, as long as the word/character(s) and and the character count are both included.

    Maybe the natural sorting could be the default, but give the user the option to turn it off with the drop down option at the top of the tree.
      • 25663 MODX Staff
      • 12,272 Posts
      That’s really pretty neat. Filed away for consideration. Thanks!
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me