Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
sorting titles by ignoring definite articles (e.g. "the", "a")
For my site I need to be able to list articles in my archive page alphabetically by title, but ignoring titles that begin with articles; “the” in particular. Instead of “The Wild One” being listed under ‘T’, I want it to be listed alphabetically along with titles beginning with ‘W’. Can conditional tags accomplish this?
And yes, simply altering my naming conventions such that the title becomes “Wild One, The” will not suffice. I need it to display properly as “The Wild One” for individual articles.
Offline
#2 2010-02-18 10:09:31
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
Look at this topic.
The different solutions would deserve a page on TXP tips.
Last edited by candyman (2010-02-18 10:13:14)
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
Problem with my “solution” in the topic candyman links is that it doesn’t handle the sorting. Possible solutions I can envision:
- Adopt chh_article_custom, or;
- Edit soo_article_filter to alter titles as above. This would allow the sorting. Then un-alter the titles for display, using a custom
title
tag, or; - Make an admin-side plugin that automatically saves the sorting form of the title into a custom field.
I might look into #3, but it goes without saying that anyone who wants to jump in first, please do.
Code is topiary
Offline
#4 2010-02-18 13:26:45
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
No 4 could be an SQL query, though I must admit my knowledge isn’t sufficient to expand the query to allow for several articles.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
th3lonius, in your archive how do you want the titles dispayed? E.g. “Wild One, The” or “The Wild One”?
Code is topiary
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
At any rate, here’s an inelegant but one-step query to strip selected leading words from titles and store the converted title in a custom field. You could then sort on the custom field, but display the original title.
Use the query with caution- It will simply overwrite whatever is currently in the chosen custom field.
- Replace the “n” in “custom_n” with the custom field # you want to use
- Add table prefix if necessary
- My version stupidly requires you to add each word you want to remove, with yet another iteration of
trim()
, but I don’t know a better straight MySQL alternative - Also note the space after the removed word
update `textpattern` set `custom_n` = trim(leading 'an ' from trim(leading 'An ' from trim(leading 'the ' from trim(leading 'The ' from trim(leading 'a ' from trim(leading 'A ' from `Title`))))))
Of course this only gets existing articles, so for subsequently added articles you’d need to re-run the query or manually enter the sortable title in the custom field.
Code is topiary
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
On my site I use a custom_field to accomplish a different goal to what you ask but can be adapted and is beneficial in other ways…
I use up a custom_field for meta page title, primarily because I don’t necessarily want the page title to also be the meta page title (the SEO company I work with then optimise those meta titles if necessary for better page rankings in search engines). You could use the same idea, it does mean you have to enter a manually customised meta page title (for example page title is The Big Cheese, meta page title is Big Cheese) but you get the added advantage of better SEO into the bargain. You then sort you articles by the meta page title custom field.
Just an idea, go with whatever method you feel works best for you.
Last edited by philwareham (2010-02-18 16:07:50)
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
jsoo wrote:
th3lonius, in your archive how do you want the titles dispayed? E.g. “Wild One, The” or “The Wild One”?
I would prefer to have the actual title e.g. “The Wild One” displayed but sorted the other way. I will try a few different methods and report back. Thanks.
philwareham: yeah, that seems to be the quickest fix but it creates more work in the long run. I’m not opposed to using a custom_field in some way but I want it to be automated. I have contributors to my site who know nothing about web development so I want my article submission process to be as simple and straightforward as possible.
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
jsoo wrote:
Of course this only gets existing articles, so for subsequently added articles you’d need to re-run the query or manually enter the sortable title in the custom field.
You could write a plugin to handle future articles automatically.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#10 2010-02-18 19:37:00
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
jsoo wrote:
Make an admin-side plugin that automatically saves the sorting form of the title into a custom field.
In your archive how do you want the titles dispayed? E.g. “Wild One, The” or “The Wild One”?
I think that the first option in the more correct: it’s a standard.
If Jeff has time to create a brand new plugiin I would suggest to consider the localization issues: in Italy the articles are i, il, la… and others…
e.g.: dolce vita, La
it would be useful an admin option panel where the user can specify the definite articles.
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
candyman wrote:
If Jeff has time to create a brand new plugiin I would suggest to consider the localization issues: in Italy the articles are i, il, la… and others…
But of course!
I decided to go with option #2. (An interesting little programming puzzle.) soo_article_filter now allows you to create alphabetical indexes as discussed.
Code is topiary
Offline
Re: sorting titles by ignoring definite articles (e.g. "the", "a")
Wow, that’s awesome. Thanks for adding this functionality to your plugin. I’m having an issue with the implementation, though. This is my code on the page:
<txp:if_variable name="sortby" value="title">
<txp:soo_article_filter index_field="index_title">
<txp:article_custom sort="custom_10 asc" form="review_archive" limit="10" />
</txp:soo_article_filter>
</txp:if_variable>
I’m using adi_gps with if_variable for sorting. I’m calling the form “review_archive” that contains my formatting for the list of articles. This is also where the custom title display is located.
<txp:permlink><txp:custom_field name="index_title" /></txp:permlink>
Last edited by th3lonius (2010-02-19 19:02:07)
Offline