Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-03-10 12:42:13

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

[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

#2 2010-03-10 13:10:20

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#3 2010-03-10 13:41:27

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#4 2010-03-10 13:41:30

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

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?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2010-03-10 16:01:27

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

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

#6 2010-03-10 16:21:10

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#7 2010-03-10 16:38:28

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

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

Board footer

Powered by FluxBB