Sort articles on people by last name

From FollowTheScore
Jump to: navigation, search

This page explains how article on people can be sorted by the last name of people although the articles' names sound like "FirstName(s) LastName".


This is a listing of all articles which describe members of the category "Fictional Character".

As you can see you will get a listing which is ordered by the first name as this is also the title of the respective articles.

With "replaceintitle" you can manipulate the appearance of the names but the order will still be determined by the article names and not by the changed label:

So we must create a sortable list which allows the user to click once for a LastName ordering:

{{#dpl:
 |replaceintitle=/([A-Za-z ]*)( [A-Za-z]+)$/,\2, \1
 |category=Fictional Character
 |format={{(!}}class=sortable\n!Fictional Characters\n{{!}}-,\n{{!}}[[%PAGE%{{!}}%TITLE%]],\n{{!}}-,\n{{!)}}
}}

which will produce the following:

Fictional Characters
Potter, Harry
Granger, Hermione Jean

The list is initially ordered by first name - but one click in the headline gives us an alphabetic ordering by last names. A second click will reverse the order (still based on last names).

To improve readability we can use our special characters for pipe and newline. And the whole thing will be easier to use if we put the code into a separate template which takes the category as an argument. We also should use a reasonable message text if htere are no articles in the category under question. Then the only thing we have to write is

{{list articles on people by last name|Fictional Character}}

And we will get the same result as above:


Fictional Characters
Potter, Harry
Granger, Hermione Jean


Looking for an empty category abrakadabra would provide the result: There are no articles in category abrakadabra