Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Today 09:47:28

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,506
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 Today 10:55:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,039
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 Today 11:49:12

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,506
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 Today 12:09:53

etc
Developer
Registered: 2010-11-11
Posts: 5,534
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 Today 13:02:26

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,039
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

Board footer

Powered by FluxBB