Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-12-24 11:08:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,122
Website GitHub Mastodon Twitter

limit words in excerpt

I am using the example on docs.textpattern.com/tags/excerpt#example-3-automatically-extract-the-excerpt-from-body-text to limit the number of words showing in excerpts but it nevertheless appears that all excerpts are preceded by p>

<txp:excerpt trim="/^\W*((?:\w+\W+){55})\w.*$/s" replace="$1&hellip;" />

Did I break the internet?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2024-12-24 16:21:01

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,122
Website GitHub Mastodon Twitter

Re: limit words in excerpt

Digging deeper into this and what appears that it is happening <txp:excerpt trim="/^\W*((?:\w+\W+){55})\w.*$/s" replace="$1&hellip;" /> trims the opening p tag (<) and does not add a closing p tag (</p>). The only way I could solve it was to add the escape="tags" attribute as in the example.

<p><txp:excerpt escape="tags" trim="/^\W*((?:\w+\W+){55})\w.*$/s" replace="$1&hellip;" /></p>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2024-12-25 00:06:00

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

Re: limit words in excerpt

This is what AI suggests:

<txp:excerpt escape="tags" trim="/^(?:<[^>]+>)*\\W*((?:\\b\\w+\\b\\W+){1,55})\\w*\\b.*$/s" replace="$1&hellip;" />

Offline

#4 2024-12-25 03:07:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,122
Website GitHub Mastodon Twitter

Re: limit words in excerpt

kuopassa wrote #338635:

This is what AI suggests:

<txp:excerpt escape="tags" trim="/^(?:<[^>]+>)*\\W*((?:\\b\\w+\\b\\W+){1,55})\\w*\\b.*$/s" replace="$1&hellip;" />...

Thanks so much, but it does not work. The p tags are misbehaving, and the word limit is not working:(

I’ll stick with what I have for now until I think of anything better.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2024-12-25 15:36:57

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 330
Website

Re: limit words in excerpt

Old plugin, still works: rss_auto_excerpt

https://forum.textpattern.com/viewtopic.php?id=18199&p=23

Offline

Board footer

Powered by FluxBB