Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-10-14 13:05:52

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Category in an article list?

Is there some reason I’m having trouble getting <txp:category /> to work on an article list?

    <txp:if_category>
      <txp:category title="1" />
    <txp:else />
      <txp:section title="1" />
    </txp:if_category>

This is in an article form. It outputs the category of the article when I’m on a category list page, but it outputs the section when I’m on an article, section listing, or the homepage. I’d like to output the category for the current article if there is one in any context. What am I missing?


Yes, I have tried turning it off and on.

Offline

#2 2016-10-14 13:29:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Category in an article list?

alesh wrote #302174:

I’d like to output the category for the current article if there is one in any context.

Not quite sure what you mean here. The current article’s category (cat 1 or 2, presently) is only available in individual article context. Whether that’s inside each article in a list, or in a single article is immaterial, it’s still tied to one article. See txp:if_article_category and txp:category1 / txp:category2

Conversely, the global category <txp:category> relates to the URL when viewing example.org/category/{optional-context/}some-cat-name. They only work on category landing pages (usually processed from your default / home page). See txp:if_category and txp:category

Does that clear anything up? Or have I missed your point?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2016-10-14 13:43:04

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Category in an article list?

Hmm… so on my homepage I can list each article’s section but not its category?

But now I’m also noticing that <txp:category /> doesn’t output anything on an individual article page? I’m putting it right in the article form.


Yes, I have tried turning it off and on.

Offline

#4 2016-10-14 14:02:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Category in an article list?

alesh wrote #302176:

so on my homepage I can list each article’s section but not its category?

You can list its category1 and/or category2 by using the appropriate tags. It doesn’t have a category, per se. It has two. The reason <txp:section> works is because an article can only reside in one section.

<txp:category /> doesn’t output anything on an individual article page?

It won’t, unless you’re viewing an article list (landing page) via the /category/cat-name on the URL. Doing that instructs Txp to “show the articles that contain the selected cat-name in either category1 or category2”. It’s a filter. The <txp:category> tag just outputs the current filter in use (i.e. the one from the URL).

Last edited by Bloke (2016-10-14 14:05:02)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2016-10-14 14:09:09

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Category in an article list?

Ahh, got it. Time to re-read pages 162 to 166. So here’s what’s going to work out for me:

    <txp:if_article_category >
      <txp:category1 title="1"/>
    <txp:else />
      <txp:section title="1" />
    </txp:if_article_category>

Thanks as ever!


Yes, I have tried turning it off and on.

Offline

#6 2016-10-14 14:22:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Category in an article list?

No worries. The number of times I scratched my head going “Why is it not outputting my article category info?!” eventually ingrained it in my head. Using if_category instead of if_article_category is a common gotcha.

I blame somewhat obtuse historical Textpattern nomenclature and tag names.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB