Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-19 11:49:27

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Automatically class first paragraph of body text?

I tried to automatically class the first body paragraph with rss_auto_excerpt, but the plugin doesn’t appear to be working properly — or I’m not righting it write. It’s not applying the class or skipping paragraphs — though it is losing the link.

<txp:rss_auto_excerpt paragraphs="1" excerptwraptag="intro" showlinkwithexcerpt="0"/>
 <txp:rss_auto_excerpt skipparagraphs="1" paragraphs="99" />

Sure, yes, I know I could use excerpts or something, but I want to use those for something else, and this must be doable “automatically”. Tell me it’s true :)

Ta!

Offline

#2 2021-03-19 12:00:25

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

Re: Automatically class first paragraph of body text?

Couldn’t you use CSS p:first-child selector instead?

Otherwise, etc_query should do it:

<txp:etc_query data='<txp:body />' replace="//p[1]@@class=my-class" />

Offline

#3 2021-03-19 12:31:24

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Re: Automatically class first paragraph of body text?

etc wrote #329366:

Couldn’t you use CSS p:first-child selector instead?

Otherwise, etc_query should do it:

<txp:etc_query data='<txp:body />' replace="//p[1]@class=my-class” />…@

Oh yeah, that did it! Thank you, etc.

Offline

#4 2021-03-19 13:08:59

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

Re: Automatically class first paragraph of body text?

Actually, even core should be able to do it now:

<txp:body trim="/^<p/" replace="<p class='my-class'" />

Offline

Board footer

Powered by FluxBB