Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-10-06 21:02:16

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Linking to category across two sections

Hello,
I have several articles belonging to a category spanning across two sections.
Is it possibile to make one link to all of them?
Thanks!…

Offline

#2 2011-10-06 23:58:34

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: Linking to category across two sections

Do you want to show a list of several articles that belong to two sections and a single category? That’s quite possible…

Offline

#3 2011-10-07 07:07:37

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Linking to category across two sections

Thanks Marc, I know I can use article_custom with section and category attributes. My understanding gap is: how do I build the link? txp:category used as link looks like it’s accepting ony one section… Gave a look to wet_link also but at no avail…

Offline

#4 2011-10-07 07:15:06

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Linking to category across two sections

As maruchan says, you can make a list that consists of articles drawn from two different sections that are assigned to a single category by using txp:article_custom and the category attribute with no section attribute set. Each article permlink (using txp:permlink) will link to the respective article in the section it is assigned to in the back-end, as you can only assign it to one section.

I can’t think of a good way to make the same article appear as an individual article in different sections without having to devise convoluted ways of overriding how txp works.

Last edited by jakob (2011-10-07 07:16:07)


TXP Builders – finely-crafted code, design and txp

Offline

#5 2011-10-07 07:22:40

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Linking to category across two sections

For example I put in the header a link txp:category name="spanningcategory" but the cms loads the home page, since it’s the default page, and in the link no section is defined…
Thanks

Offline

#6 2011-10-07 08:10:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Linking to category across two sections

txp:article is context sensitive so it responds to the ?c=spanningcategory category in the URL but also to the section you happen to be in. If you use txp:article, it will only ever show you a list of articles in that section. If you are linking to a category page using txp:category link="1" and don’t specify either a section="my-section-name" or this_section="1" attribute, the link will go to the homepage with ?c=spanningcategory set. In that case txp:article will list articles from all sections where you have “on front page” set to “yes” in the “Presentation > Sections” pane.

If you want to list articles from several sections from within a section, you’ll need to build your category links like this:

<txp:category name="spanningcategory" link="1" title="1" section="my-section-name" />

so that you get links that go to www.mydomain.com/my-section-name?c=spanningcategory.

On the page template for your section to list them you’ll need to use:

txp:article_custom category='<txp:category />' limit="999" ...

to insert the category as a filtering attribute (as article_custom is not context-aware) Note the use of single quotes for tags in tags.

Last edited by jakob (2011-10-07 08:10:42)


TXP Builders – finely-crafted code, design and txp

Offline

#7 2011-10-07 08:36:44

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Linking to category across two sections

Thanks jakob, therefore you can’t print same category from multiple sections, unless it’s on the homepage, since txp:category link="1" accepts only one section right?
I guess I could use a search querystring

Offline

#8 2011-10-07 09:24:21

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Linking to category across two sections

It depends what you mean by “print”. It would help to know your use case.

A hypothetical situation: say you have product articles assigned to categories, e.g. “t-shirts”, “shorts”, “caps” … assigned to sections by manufacturer, e.g. “nike”, “addidas”, “puma” … and now you want to make pages that show you a list of all t-shirts, all shorts, etc.

  • Make an arbitrary section (that won’t have any content of its own) for the category views, e.g. product-type.
  • Create category links to www.mydomain.com/product-type?c=t-shirts, www.mydomain.com/product-type?c=shorts, www.mydomain.com/product-type?c=caps etc. You can do that manually or use <txp:category name="xyz" link="1" title="1" section="product-type" /> (if you want to build a dynamic list of these categories, use txp:category_list).

Create a page template for product-type and include:

txp:article_custom category='<txp:category />' limit="999" ...

as described above. That will grab the category in the url and use it for filtering results with txp:article_custom. Because txp:article_custom is not context-sensitive and you have not specified a section, it will list articles that are assigned to the category that you have in your URL from all sections/manufacturers. The links to the respective article will still go to the section they are assigned to in the write tab.

Last edited by jakob (2011-10-07 09:25:45)


TXP Builders – finely-crafted code, design and txp

Offline

#9 2011-10-07 13:34:00

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Linking to category across two sections

That’s what I was looking for! :)
Thank you so much!

Offline

Board footer

Powered by FluxBB