Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-28 23:49:49

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Creating separated link list with category headers

I would like to create a link list, sorted by category, and also visually separated by category, preceeding every category block by the category’s name as a header.

At the moment I have a plain link list produced by <txp:linklist form="Links" sort="category asc" />

The output is…

Link 1
Link 1 description

Link 2
Link 2 description

etc.

So far so good, but I’d like it to render like this:

Category 1 Name

Link 1
Link 1 description

Link 2
Link 2 description

Category 2 Name

Link 1
Link 1 description

Link 2
Link 2 description

etc.

I can’t figure out, how to break the list apart per category and render the respective headers.
Any ideas how to achieve that?

PS: I know, I could hard code these separate lists, but I want new link categories to show up automatically.

Last edited by masa (2009-09-28 23:55:12)

Offline

#2 2009-09-28 23:55:54

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

Re: Creating separated link list with category headers

Using txp:if_different?

<txp:if_different><txp:link_category /></txp:if_different>
... other link tags...

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2009-09-29 00:06:38

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Creating separated link list with category headers

Julián,

thanks!
I was afraid, someone would suggest txp:if_different – it’s one of the few tags I never use, nor have I managed to quite understand how it works  :-)

But I’ll give it a try.

Offline

#4 2009-09-29 00:18:36

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Creating separated link list with category headers

Julián,

you’re a genius – it works  :-)

My new Links form called from the same txp:linklist tag:

<txp:if_different><h3><txp:link_category /></h3></txp:if_different>
<p><txp:link /><br />
<txp:link_description /></p>

Edit: corrected the first line as per Els’ suggestion below.

Last edited by masa (2009-09-29 17:01:44)

Offline

#5 2009-09-29 16:22:40

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

Re: Creating separated link list with category headers

Change the first line to

<txp:if_different><h3><txp:link_category /></h3></txp:if_different>

or you’ll end up with lots of empty <h3></h3> tags :)

Offline

#6 2009-09-29 17:00:02

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Creating separated link list with category headers

Hey Els,

thanks for that, you are so right!
I thought it didn’t look quite right, but it was getting late yesterday.

Offline

Board footer

Powered by FluxBB