Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-17 01:39:51

osugodfan
Member
Registered: 2008-03-16
Posts: 16

Getting crazy with a Custom field. Can you help me figure this out?

Honestly, I only need one custom field for this to work, I think. The trick is getting it all to play nicely. The idea has to do with a Directory of sorts on an intranet site. I’m kinda stumped on how to pull this off.

An article of every employee, using article_image for that person’s mugshot…I mean photo.
One custom field: denoting the last initial of the person.

A row across the top of every letter of the alphabet that has an article where custom_field name=“last_initial” is equal to the letter. That is, you might have A B C D E F K L M

notice theirs no J, because hypothetically, there’s nobody at the company who’s last name starts with J.

Does any of this make sense?

User clicks on the letter and is given a list of the folks whose last name begins with that letter. I’m using this in conjunction with jQuery Tabs for the full effect. Right now, here’s all I got.

<div id="alphacontainer">
	<ul>
		<li>
                <txp:if_custom_field name="Last_Initial">
                <a href="<txp:custom_field name="Last_Initial"/>_list"><txp:custom_field name="Last_Initial"/></a>
                </txp:if_custom_field>
               </li>
	</ul>
		<div id="<txp:custom_field name="Last_Initial"/>list" class="alpha">
		Test
		</div>
</div>

I’m kind of stumped on how exactly to make this work, and any help would be appreciated. Would basicly love it I could use txp to automagically fill in the content based on meeting certain criteria.

Thanks!

Offline

#2 2009-04-17 07:25:09

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Getting crazy with a Custom field. Can you help me figure this out?

Try something like this:

<div id="alphacontainer">

<txp:article_custom wraptag="ul" section="your-section" sort="custom_1 asc" limit="999">
	<txp:if_different>
		<li><a href="#<txp:custom_field name="Last_Initial" />list"><txp:custom_field name="Last_Initial" /></a></li>
	</txp:if_different>
</txp:article_custom>

<div>
<txp:article_custom section="your-section" sort="custom_1 asc" limit="999">
	<txp:if_different>
		</div>
		<div id="<txp:custom_field name="Last_Initial" />list" class="alpha">
	</txp:if_different>
		<p><txp:title /></p>
</txp:article_custom>
</div>

</div>

Offline

#3 2009-04-17 07:26:00

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,730
Website

Re: Getting crazy with a Custom field. Can you help me figure this out?

That sounds workable but I imagine you could automate this a step further using a plugin such as sab_substr (with no trailing attribute) to automatically grab the initial from your surname field* and then txp:if_different to generate the top bit of your list for each letter (see this faq article too). if_different only inserts the relevant code if the content is different to the last time, so if you sort by your surname custom field, that code will only appear when there’s a new initial. As it only checks against articles, it will only show initials where there are actual articles with that initial.

*So to grab the initial of the surname you would need <txp:sab_substr limit="1" trail=""><txp:custom_field name="surname" /></txp:sab_substr>. If your forename and surname is in a single field, it would still be possible to extract the initial, but you’d need a small php snippet to grab the right initial (maybe pax_grep helps here or look at php’s explode and substr functions to break the name open into individual words, then grab the initial of the last word).

EDIT: Els is quicker again :-) Maybe it still helps.

Last edited by jakob (2009-04-17 07:26:46)


TXP Builders – finely-crafted code, design and txp

Offline

#4 2009-04-20 23:00:39

osugodfan
Member
Registered: 2008-03-16
Posts: 16

Re: Getting crazy with a Custom field. Can you help me figure this out?

OMG!

That worked just perfectly. Thanks so much!

Offline

Board footer

Powered by FluxBB