Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-11 05:20:48

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 228
Website

How to exclude articles by url_title partial match

Is there a way to use article_custom tag to exclude articles based on how url_title ends? I’d like to exclude those that end with -mobile or -touch.

Offline

#2 2021-06-11 07:16:53

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

Re: How to exclude articles by url_title partial match

Sadly, hiding via <txp:if_custom_field name="url_title" /> seems to be the only option. I remember several discussions on adding url_title attribute, but for some reason that has not been done yet. Maybe in 4.8.8?

Edit: please test if you can.

Offline

#3 2021-06-11 07:28:21

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 228
Website

Re: How to exclude articles by url_title partial match

Oh right, etc, thanks. :-) I’ll test smd_query plugin next.

Offline

#4 2021-06-11 08:15:26

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

Re: How to exclude articles by url_title partial match

Ach, forgot about it. Good catch, etc. That’s a lovely addition… and substring comparisons in the escape attribute too, woohoo!


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 2021-06-11 12:09:05

pexman
Member
Registered: 2016-02-27
Posts: 61

Re: How to exclude articles by url_title partial match

Plugin aks_article, <txp:aks_article /> You have the option ‘exclude’, a rewritten core functions extended article_custom tag, author makss

Offline

#6 2021-06-11 12:14:59

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 228
Website

Re: How to exclude articles by url_title partial match

^ Yes, you’re correct. That’s exactly what did the job. :-) Unfortunately makss’ website is gone, so I had to use an old version of that plugin (0.3.2).

Offline

#7 2021-06-11 12:16:27

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

Re: How to exclude articles by url_title partial match

Bloke wrote #330432:

substring comparisons in the escape attribute too, woohoo!

Thanks! Still unsure how to treat negative values: should escape="-3" applied to abcdefgh return abcde, defgh or fgh?

pexman wrote #330436:

Plugin aks_article, <txp:aks_article /> a rewritten core functions extended article_custom tag

It might be very out of date now… And out of curiosity, how does one exclude articles by url_title?

Offline

#8 2021-06-11 12:27:53

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

Re: How to exclude articles by url_title partial match

etc wrote #330438:

Still unsure how to treat negative values: should escape="-3" applied to abcdefgh return abcde, defgh or fgh?

Yeah, tricky. Without the concept of ‘length’, the offset itself is always going to be anchored to either end of the string, so for consistency I would go with fgh, which mirrors PHP’s implementation.

  • A positive value crops N characters after the given number and returns the string from the start up until that point. i.e. the first N characters.
  • A negative value crops N character before the given number, as counted from the end of the string, and return the string from that point up until the end of the string. i.e. the last N characters.

That seems logical to me.


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

#9 2021-06-11 12:39:33

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

Re: How to exclude articles by url_title partial match

Bloke wrote #330439:

That seems logical to me.

I agree on escape="+n" returning the first n characters, seems useful. But is there any use for the last n characters? I’d rather vote for defgh, so one could easily split strings.

Sorry for hijacking the thread.

Offline

#10 2021-06-11 13:06:22

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

Re: How to exclude articles by url_title partial match

defgh can be obtained by escape="-5" :)

But yeah, I see what you mean. Okay, maybe my first example was wrong above. With input abcdefgh how about this concept instead:

  • escape="+4": defgh
  • escape="-3": fgh
  • escape="+4..2": de
  • escape="-3..2": fg

So +/-offset..length instead (with a two- or three-dot delimiter, or another delimiter of choice), counting from 1/-1 from each end. That differs from PHP, which starts at 0 from the start and -1 from the end, but I think that’s confusing.

Without the length, you get ‘to the end of the string’ returned.

Does that work for sub-splitting, or does it conflict with other escape values? Or are there corner cases that it doesn’t catch?

Last edited by Bloke (2021-06-11 13:12:03)


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

#11 2021-06-11 13:16:07

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

Re: How to exclude articles by url_title partial match

Another wildcard… is this more closely aligned with trim than escape? e.g. given https://example.org/section/article as input:

  • trim="+20": /section/article
  • trim="+20" replace="https://example.com": https://example.com/section/article

?? Being able to pair it with replace seems kinda desirable.

EDIT: fix idiocy.

Last edited by Bloke (2021-06-11 13:20:03)


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

#12 2021-06-12 08:36:21

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

Re: How to exclude articles by url_title partial match

Bloke wrote #330441:

So +/-offset..length instead

Nice idea, especially since we already use these dotted notations for ranges in id and other attributes. Should be doable.

Bloke wrote #330442:

Another wildcard… is this more closely aligned with trim than escape?

Probably, but trim can already handle regex, so this wouldn’t add much value.

Offline

Board footer

Powered by FluxBB