You are not logged in.
Hi Folks ;)
Here it is: I’ve got some articles title formed with two words (First Name Last Name).
Do you think it’s possible to sort articles on the second word (Last Name) only?
All ideas are welcome.
Tks by advance,
Last edited by Pat64 (2012-07-09 06:04:43)
One way is to use a custom field where you could enter “surname, name” and then use article OR article_custom to sort them…
>Edited to add:
<txp:article_custom sort="custom_3 desc"> <txp:if_custom_field name="custom_3"> <txp:page_title /> </txp:if_custom_field> </txp:article_custom>
Last edited by colak (2012-07-07 17:56:57)
Patrick, you can do this with soo_article_filter at the expense of an additional (sub-)query. Have a look at this thread.
TXP Builders – finely-crafted code, design and txp
While technically possible, due to performance, you should use a dedicated field for last name, e.g. store it in a custom field as instructed by Yiannis. Doing this, or any, type of processing for sorting eats a lot resources. The more articles you have, the less stable your site would become.
Please, consider storing last name separately even if it is more work. If you still want to pursue this, it is doable. You can in general run any processing in MySQL ORDER BY statement, where then the resulting value is used as the order criterion. E.g.
SUBSTRING_INDEX(Title, ' ', -1)
Above would split the last word out of the Title. But now comes the certain obstacles. Textpattern does necessary escaping in it’s tags which prevents using that directly in article or article_custom tags. This leads us to either doing a separate query that gets the matching article IDs and passes results to the article_custom tags, or we do a completely custom listing with something like smd_query. I like the sound of native -ish approach so:
<!-- Gets IDs in correct order -->
<txp:variable name="ids"><txp:php> echo implode(',', safe_column('ID', 'textpattern', "1=1 ORDER BY SUBSTRING_INDEX(Title, ' ', -1)")); </txp:php></txp:variable>
<!-- Passes the list of sorted IDs to article custom -->
<txp:article_custom id='<txp:variable name="ids" />' sort='FIELD(ID, <txp:variable name="ids" />) asc'> <txp:title /> </txp:article_custom>
Rah-plugins | What? I’m a little confused… again :-)
Yo Guys. Tks for your quick replies :)
Yeah our friends custom_field can make the trick but… in this project I don’t use it at all! Ok you are saying: strange, you’re crazy Pat.
The reason why is that my client is not very friendly with computers (very basic usages :(
So, I chosen to organise the website based on some extractions of title parts (a kind of query as Jukka – my personal PHP professor – said)
The only thing my client has to do now is to write his headlines based on a pre-defined scheme: pretty simple and all works perfectly (categories filter, articles extraction from other sections, and so on).
Now what do you think I should do?
One of the problems I foresee is the ability of php to recognise names V surnames. You could have something like
I think that giving the custom_field a user friendly title (alphabetise might be one), will produce more accurate results.
<!-- Gets IDs in correct order --> <txp:variable name="ids"><txp:php> echo implode(',', safe_column('ID', 'textpattern', "1=1 ORDER BY SUBSTRING_INDEX(Title, ' ', -1)")); </txp:php></txp:variable> <!-- Passes the list of sorted IDs to article custom --> <txp:article_custom id='<txp:variable name="ids" />' sort='FIELD(ID, <txp:variable name="ids" />) asc'> <txp:title /> </txp:article_custom>
Hey, hey, Man. Now you know why I love you :D
Thanks lot Jukka. As always you show me the best way in order to make the world better.
Have a nice day, Mate.
Edit: So, despite the general view, I will continue to make websites :D
Last edited by Pat64 (2012-07-08 11:39:49)