WordPress Plugin: Sort wp_list_pages-Generated Page Lists by Last Name

Subscribe

Available for download from the WordPress plugin directory.

Once again working with its partner Ryan Jarrett, Studio Hyperset has released a new WordPress plugin aimed at archivists, as well as other WordPress user-developers, who use people’s names as page titles.

By default, WordPress sorts wp_list_pages-generated page lists according to the first letter of the first word of the page title. In most cases, this isn’t a problem (though the issue of sorting by initial [in]definite articles — the, an, a — seems to cry out for a plugin in its own right). When user-developers title a series of pages with people’s names, however, neither the native wp_list_pages function nor any of its parameters allow WordPress user-developers to organize page lists according to best-practice forms of Western alphabetization, that is, by the first letter of an individual’s last name, e.g.:

Preferred

  1. Doe, Zane
  2. Zoë, Jane

vs.

WordPress Default

  1. Jane Zoë
  2. Zane Doe

SH‘s “Sort Page List by Last Name” WordPress plugin alphabetizes wp_list_pages-generated page lists by the last word of the page title. In this way, it can be used generally to sort page lists by the last word of a page title or — more narrowly and more likely, when these titles are people’s names — by last name.

The plugin is available in the WordPress Plugins Directory and on SH‘s Google code project site, and it can be seen in action in the “Our History” section of SH‘s Women’s Research Institute of Nevada site. (Select either of the sorting options to see the affected lists.)

Usage
After installing and activating, developers can order any wp_list_pages-generated page list by surname — or, more generally, last word — using the sortbylastname=1 parameter, e.g., <?php wp_list_pages('title_li=&sortbylastname=1'); ?>. (A 0 will [temporarily] disable the plugin.)

Developer Notes
SH is quite interested in the ways in which publishers use the Sort Page List by Last Name plugin. Please share ideas and usage notes in the comments below.

Additionally, developers should be aware of a WordPress quirk that can undermine the plugin’s functionality.

Line 14 of the plugin extracts each separate line of HTML from the original wp_list_pages output and puts it into an array called $lines. The n parameter tells the explode command that each line ends with a carriage return. However, as of WordPress 3.2.1, the explode command assumes each line ends when it finds an n. As such, if developers edit the plugin using the WordPress code editor, they should add an extra backslash () in front of the n before saving the file (e.g, $lines = explode("\n", $val);). The line will revert to $lines = explode("n", $val); on save.

Future Builds
At present, the plugin’s aimed at WordPress developers. As demand warrants, future builds may add an admin metabox to increase ease-of-use by non-developer WordPress users.

SH may also expand the plugin to address the problem of sorting pages according to initial (in)definite article (“the,” “a,” “an,” &tc.), engineer it to properly sort compound surnames with prefixes (“Van,” “Von,” “Los,” “St. John,” &tc.); give users the option of sorting lists in reverse order, that is, Z-A; and increase compatibility with non-Western alphabets and non-Western forms of alphabetization.

Discussion & Support
For plugin support, feedback, and troubleshooting, visit this link or click the “Feedback” tab on the left-hand side of your browser window. To learn about other Studio Hyperset WordPress plugins, click here. To learn about other Studio Hyperset code projects, click here.

Build great relationships with your customers and teammates

Download this eBook

    Learn how effective communication systems can help you build great relationships with customers and teammates.

Quimby Melton

Founder/President

Quimby is the founder and president of Studio Hyperset. He started Studio Hyperset in 2006 after studying Transatlantic literature and culture, new media, and humanities computing at the Universities of Georgia (AB, 00) and Nevada, Las Vegas (MA, 03; PhD, 08). He has a background in literary studies, media production, front-end development, and project management. His current primary duties involve helping clients frame solutions that meet their needs; scoping and managing Studio Hyperset's growth strategy and business development pipeline; finding and developing talent; and, most importantly, supporting the SH team.