Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
[Solved] if_different brain teaser
I have a number of portfolio articles that use a custom field (custom_6 = “Client_Company”) to store the name of the client for whom the work was done.
Multiple projects have been done for some clients, so some articles share the same client name in this field.
I want to display a list of clients in the following way:- show each client’s name only once – simply skip past each subsequent article for a client once the first one has been displayed
- sort by posted date
- display custom_6 as a permlink
Sounds easy enough, doesn’t it?
if_different
is the obvious option for stripping duplicates. To use it effectively I need to sort by custom field instead of date.
<txp:article_custom section="work" limit="100" sort="custom_6"><txp:if_different><txp:custom_field name="Client_Company" />,</txp:if_different></txp:article_custom>
This gives me a list of client names, free of duplicates, but they aren’t sorted in the order I’d like and they aren’t permlinked.
I muddled around creating an array of these articles in a variable.
<txp:variable name="clients" value='<txp:article_custom section="work" limit="100" sort="custom_6"><txp:if_different><txp:custom_field name="Client_Company" />,</txp:if_different></txp:article_custom>' />
Then, if I could convert this list of custom field names to article IDs (without reintroducing the duplicates) I could use variable contents in a <txp:article_custom id="" />
call.
I may be going around in circles here. Can anyone guide me out of the woods?
Last edited by pieman (2010-03-10 16:04:24)
Offline
Re: [Solved] if_different brain teaser
Off the top of my head, not tested:
<txp:article_custom section="work" limit="100" sort="Posted asc">
<txp:if_variable name='<txp:custom_field name="Client_Company" />' value="1">
<txp:else />
<txp:variable name='<txp:custom_field name="Client_Company" />' value="1" />
<txp:permlink><txp:custom_field name="Client_Company" /></txp:permlink>,
</txp:if_variable>
</txp:article_custom>
Sorry, too early in the morning. The sorting is a bit of a puzzle.
Edit: Take two:
I don’t know if variable
allows a name with spaces in it, and you’ll have to strip the final comma somehow.
Last edited by jsoo (2010-03-10 14:10:54)
Code is topiary
Offline
Re: [Solved] if_different brain teaser
Version with smarter commas
<txp:article_custom section="work" limit="100" sort="Posted asc">
<txp:if_variable name='<txp:custom_field name="Client_Company" />' value="1">
<txp:else />
<txp:if_variable name="break" value="">
<txp:variable name="break" value=" ," />
<txp:else />
<txp:variable name="break" />
</txp:if_variable>
<txp:variable name='<txp:custom_field name="Client_Company" />' value="1" />
<txp:permlink><txp:custom_field name="Client_Company" /></txp:permlink>,
</txp:if_variable>
</txp:article_custom>
Last edited by jsoo (2010-03-10 14:10:41)
Code is topiary
Offline
Re: [Solved] if_different brain teaser
Hi pieman.
Then, if I could convert this list of custom field names to article IDs (without reintroducing the duplicates) I could use variable contents in a <txp:article_custom id=”“ /> call.
But, still, how will you be sorting those IDs in the desired order? I mean, you will have your list of article IDs, but how will you automagically sort them in the order you would like to have them sorted?
Also, you mention you want custom_6 displayed as a permalink… pointing to… where?
Offline
Re: [Solved] if_different brain teaser
jsoo wrote:
Version with smarter commas
Thanks Jeff. That works! I was about to head off into a world of pain banging my head against smd_query for a few hours, but there was a much simpler way. Making a variable named after each client is a sweet move. I only wish I was smart enough to have come up with it myself.
The <txp:variable name="break" />
part of your suggestion seems not to do much. The output it the same without it. Maybe I confused you with my description of the problem.
But anyway, I am well chuffed. Thanks again, and to you also Maniqui.
Offline
Re: [Solved] if_different brain teaser
pieman wrote:
The
<txp:variable name="break" />
part of your suggestion seems not to do much.
No, it wouldn’t. I am forever getting confused about doing if_variable
on an uninitialized variable. Maybe this:
<txp:article_custom section="work" limit="100" sort="Posted asc">
<txp:if_variable name='<txp:custom_field name="Client_Company" />' value="1">
<txp:else />
<txp:if_variable name="break" value="1"> ,<txp:else /><txp:variable name="break" value="1" />
</txp:if_variable>
<txp:variable name='<txp:custom_field name="Client_Company" />' value="1" />
<txp:permlink><txp:custom_field name="Client_Company" /></txp:permlink>
</txp:if_variable>
</txp:article_custom>
Last edited by jsoo (2010-03-10 16:24:14)
Code is topiary
Offline
Re: [Solved] if_different brain teaser
No worries Jeff. I only used the commas originally to create a pseudo-array in the variable. My problem is solved without them.
Offline
Pages: 1