Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-02-02 22:25:57

amordecosmos
Member
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 79
Website

Display articles only with empty category

This seems like a question from 2004 but…

I want to use txp:article but exclude one particular category. So, everything but CatX.

Obvs, I could use txp:if_article_category but I want to page through normally.

What am I missing?

Offline

#2 2021-02-03 05:40:46

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,724
Website GitHub Twitter

Re: Display articles only with empty category

Would the snippet below work?

<txp:article>
<txp:if_article_category name="CatX" not>
do something
</txp:if_article_category>
</txp:article>

Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#3 2021-02-03 07:29:27

etc
Developer
Registered: 2010-11-11
Posts: 4,512
Website GitHub

Re: Display articles only with empty category

amordecosmos wrote #328499:

I want to use txp:article but exclude one particular category.

Just say it:

<txp:article exclude category="CatX" />
<!-- or maybe "catx" -->

Offline

#4 2021-02-03 08:40:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,724
Website GitHub Twitter

Re: Display articles only with empty category

etc wrote #328501:

Just say it:

<txp:article exclude category="CatX" />...

Where is the like button:)


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#5 2021-02-03 09:42:16

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,483
Website GitHub Twitter

Re: Display articles only with empty category

Here it is Yiannis ;)

👍


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#6 2021-02-03 22:12:31

amordecosmos
Member
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 79
Website

Re: Display articles only with empty category

etc wrote #328501:

Just say it:

<txp:article exclude category="CatX" />...

Oh, I wish. But txp:article exclude doesn’t work that way

I can do <txp:article exclude = 'category2' /> and all articles that have an article category 2 will be excluded. But It won’t exclude a specific category.

Offline

#7 2021-02-03 22:21:44

amordecosmos
Member
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 79
Website

Re: Display articles only with empty category

colak wrote #328500:

Would the snippet below work?

<txp:article>
<txp:if_article_category name="CatX" not>
do something
</txp:if_article_category>
</txp:article>

THANK you for introducing me to that parameter not. Wonderful – but also undocumented.

This snippet works fine for excluding CatX – but it can mess up the normal pagination of txp:article.

Imagine you have 100 articles. The first 5 are tagged ‘CatX’ then 20 that are not, then 50 that are.

If you page through your articles using <older><newer>, the first page will only have five articles, the next two will be fine, then the viewer will have five blank pages before coming to articles again.

Offline

#8 2021-02-03 22:35:50

etc
Developer
Registered: 2010-11-11
Posts: 4,512
Website GitHub

Re: Display articles only with empty category

amordecosmos wrote #328506:

Oh, I wish. But txp:article exclude doesn’t work that way

What is txp version you have tested?

Offline

#9 2021-02-03 22:37:57

amordecosmos
Member
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 79
Website

Re: Display articles only with empty category

What is txp version you have tested?

4.8.4

Offline

#10 2021-02-03 22:46:18

etc
Developer
Registered: 2010-11-11
Posts: 4,512
Website GitHub

Re: Display articles only with empty category

Ah yes, you are right, <txp:article /> does not accept category attribute (<txp:article_custom /> does). That’s annoying, but this tag was engineered like this, it inherits its category from URL. Scratching head…

Offline

#11 2021-02-03 23:03:05

etc
Developer
Registered: 2010-11-11
Posts: 4,512
Website GitHub

Re: Display articles only with empty category

Not ideal, but you can do it in two passes:

<txp:variable name="ids">
    <txp:article_custom exclude category="catx" fields="thisid" break="," limit="999">
        <txp:article_id />
    </txp:article_custom>
</txp:variable>

<txp:article id='<txp:variable name="ids" />' />

Offline

#12 2021-02-03 23:28:27

amordecosmos
Member
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 79
Website

Re: Display articles only with empty category

etc wrote #328511:

Not ideal, but you can do it in two passes:

<txp:variable name="ids">...

Hey, that worked! Thank you.

Offline

Board footer

Powered by FluxBB