Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-07-07 17:03:46

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,015
Website

[Solved by Jukka] Article sort order on second word of the title?

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)


Patrick.
Txp Tricks & Tips by french users : http://txp-fr.net | G+
@Devs : Can’t find the punched tape version of TXP and I need it!
Happy user of TXP 1.0RC1 on a Sinclair ZX spectrum server

Offline

#2 2012-07-07 17:47:37

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,933
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

Hi Patrick

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)


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Offline

#3 2012-07-07 18:40:06

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 1,898
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

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

Offline

#4 2012-07-07 18:44:01

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

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 :-) <txp:is_god />

Offline

#5 2012-07-08 07:55:19

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,015
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

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?

  • Rebuilt all the website based on custom_fields
  • Use WordPress
  • Stop making websites

Cheers,


Patrick.
Txp Tricks & Tips by french users : http://txp-fr.net | G+
@Devs : Can’t find the punched tape version of TXP and I need it!
Happy user of TXP 1.0RC1 on a Sinclair ZX spectrum server

Offline

#6 2012-07-08 08:58:54

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,933
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

One of the problems I foresee is the ability of php to recognise names V surnames. You could have something like

  • name name Surname
  • name Surname Surname
  • and other combos

I think that giving the custom_field a user friendly title (alphabetise might be one), will produce more accurate results.


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Offline

#7 2012-07-08 11:36:49

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,015
Website

Re: [Solved by Jukka] Article sort order on second word of the title?

Gocom wrote:

<!--
	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)


Patrick.
Txp Tricks & Tips by french users : http://txp-fr.net | G+
@Devs : Can’t find the punched tape version of TXP and I need it!
Happy user of TXP 1.0RC1 on a Sinclair ZX spectrum server

Offline

Board footer

Powered by FluxBB