Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-11-05 09:47:28

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,508
Website

article_custom, excluding a specific category

I was trying generating a list of all articles (on a list page), except those from on specific category (named foo2 in the samples below).

The best I could come up:

<txp:article_custom limit="300" allowoverride="0" wraptag="ol" break="" class="overview-list" sort="section desc">
<txp:if_article_category not name="foo2">
  <li><h2 id="als-<txp:article_id />"><a href="<txp:permlink />"><txp:title /></a></h2>
  <txp:excerpt escape="textile" />
  <footer><p class="article-meta">Posted: <time datetime="<txp:posted format="%Y-%m-%d" />"> <txp:posted /></time><!-- utc +9--> <txp:section /></p>
</footer></li>
</txp:if_article_category>
</txp:article_custom>

That feels a little bloated. I would have thought using the not attribute or the exclude attribute would have helped in, as in:

<txp:article_custom form="all_article_list" limit="300" allowoverride="0" wraptag="ol" break="" class="overview-list" sort="section desc" not category="foo2" />

But no luck.

Or with exclude="field(Category1,foo2), or exclude='<txp:category name="foo2") />'.But perhaps I don’t understand the syntax to use in that case?

Incidentally, with my working markup, I see lots (150+) of blank lines of markup where the excluded articles would have been.

 <li><h2>……………</h2></li>
(blank line – ~150 times, there are about 45 articles in the offending category)
<li>

That is like the <txp:if_article_category not name="foo2"> outputs a blank line for each article in that foo2 category. Not a disaster, gzip zaps those away, but feels a little dirty. trim didn’t seem to help.

TXP 4.9-dev, PHP 8.3 and 8.4


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#2 2025-11-05 10:55:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,041
Website GitHub

Re: article_custom, excluding a specific category

Try <txp:article_custom category="foo2" exclude> and then the rest of your attributes. That should exclude it, though I don’t know if it works without specifying which category1/2 to exclude.


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 2025-11-05 11:49:12

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,508
Website

Re: article_custom, excluding a specific category

That indeed works (without specifying which of category ½) and simplify the markup. Thank you. I need to try to understand the mechanism better.

My actual content construct is more complicated than used above: txp:if_exerpt … txp:else txp:if_description … and some more. That gives us a nice annotated list of articles (the section displaying it is not public).


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#4 2025-11-05 12:09:53

etc
Developer
Registered: 2010-11-11
Posts: 5,538
Website GitHub

Re: article_custom, excluding a specific category

phiw13 wrote #341096:

Incidentally, with my working markup, I see lots (150+) of blank lines of markup where the excluded articles would have been.

<li><h2>……………</h2></li>...

That is like the <txp:if_article_category not name="foo2"> outputs a blank line for each article in that foo2 category. Not a disaster, gzip zaps those away, but feels a little dirty. trim didn’t seem to help.

This probably comes from the surrounding linebreaks, try setting trim on <txp:article_custom /> itself (or regex trim/replace?)

Bloke wrote #341097:

Try <txp:article_custom category="foo2" exclude> and then the rest of your attributes. That should exclude it, though I don’t know if it works without specifying which category1/2 to exclude.

Valueless exclude will exclude all ‘filter’ atts (section, category, etc). One can fine-tune it like

<txp:article_custom section="to_include" category="to_exclude" exclude="category" match="Category1" />

Offline

#5 2025-11-05 13:02:26

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,041
Website GitHub

Re: article_custom, excluding a specific category

etc wrote #341099:

Valueless exclude will exclude all ‘filter’ atts (section, category, etc). One can fine-tune it [with match].

That’s really flexible. Sooo many things to document when 4.9.0 drops soon!


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

#6 Yesterday 06:32:35

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,508
Website

Re: article_custom, excluding a specific category

etc wrote #341099:

This probably comes from the surrounding linebreaks, try setting trim on <txp:article_custom /> itself (or regex trim/replace?)

Valueless exclude will exclude all ‘filter’ atts (section, category, etc). One can fine-tune it like

<txp:article_custom section="to_include" category="to_exclude" exclude="category" match="Category1" />...

That works equally well. When articles either have the foo2 category as Category1 or Category2 then simply omitting the match attribute is the way, I think. match="Category1, Category2" appears to be the default.

Omitting the value for the exclude attribute offers interesting possibilities


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#7 Yesterday 12:38:50

etc
Developer
Registered: 2010-11-11
Posts: 5,538
Website GitHub

Re: article_custom, excluding a specific category

Just to make things clearer, the global not attribute is tag agnostic (like all global attributes), and vice versa. It does not ‘see’ category="foo2" and other attributes in

<txp:article_custom ... not category="foo2" />

Its role is just to blindly switch true/false parts on tags output:

<txp:evaluate query="2*2=4">
    right
<txp:else />
    wrong
</txp:evaluate>
<!-- right -->

<txp:evaluate not query="2*2=4">
    right
<txp:else />
    wrong
</txp:evaluate>
<!-- wrong -->

In the second block, <txp:evaluate /> itself is not aware of the presence of not, and would output parse($thing, true), since 2*2=4. But parse() takes not into account and returns parse($thing, false) instead. If a tag does not use parse() function for output, not has no (expected) effect on it.

Offline

Board footer

Powered by FluxBB