Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-17 17:28:38

lindabb
Member
Registered: 2023-02-17
Posts: 132

exclude article

Hello,
How I exclude article with id in :

<txp:article class=“article-list” form=“article_listing” limit=“10” wraptag=“ul” />

this is from the demo that comes with textpattern installation.
also, I like to add like first 100 characters from the article body below the title, with read more.

Thank you

Offline

#2 2023-02-17 21:35:20

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

Re: exclude article

Hello, welcome to the forum.

To exclude some articles, pass their ids to exclude attribute:

<txp:article exclude="1,2,3" class="article-list" form="article_listing" limit="10" wraptag="ul" />

To truncate the article body, avoiding cutting inside a word, if possible:

<txp:body  trim="/(?<=^.{95})(\w{0,5})[\s\w].+$/" replace='$1... <txp:permlink>Read more</txp:permlink>' />

Hope it helps.

Online

#3 2023-02-17 22:18:47

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: exclude article

Thank you so much, worked perfectly after fixed replaced ” with “

Offline

#4 2023-02-17 22:33:26

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: exclude article

the exclude worked, but the body for some reason not showing

<txp:article exclude="1,6" class="article-list" form="article_listing" limit="10" wraptag="ul" >  
                       <txp:body trim="/(?<=^.{95})(\w{0,5})[\s\w].+$/" replace='$1... <txp:permlink>Read more</txp:permlink>' />   
                       </txp:article>

Thank you

Offline

#5 2023-02-18 08:37:12

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

Re: exclude article

lindabb wrote #334657:

the exclude worked, but the body for some reason not showing

<txp:article exclude="1,6" class="article-list" form="article_listing" limit="10" wraptag="ul" >...

You should probably remove form attribute?

Edit: Also remove eventual HTML tags first to avoid broken markup:

<txp:body escape="tags" ... />

Online

#6 2023-02-18 16:37:10

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: exclude article

… And maybe the link <txp:permlink>Read more</txp:permlink> have to be placed outside the <txp:body /> tag (otherwise, the link tag is escaped).


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#7 2023-02-18 22:43:11

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: exclude article

Hello,

Thank you all for your suggestions, none of above worked, as I said the exclude part worked,
but list of articles title (or header) with first 100-150 characters with read me didn’t work, will be nice if some post real working example.
needed example: list of all articles (titles) with ability to exclude articles by ids, with h1 and then show part of the body first 100-150 characters with read more link.

Thank you for any help I get

Offline

#8 2023-02-18 22:59:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: exclude article

I had no luck with regex variant either in txp 4.8.8, though the regex does work very nicely (see here).

@lindabb, See this post (and the thread above it) for another way that does currently work, though it’s not quite as neat because it can stop mid-word:

<txp:evaluate query='substring("<txp:body escape="tags" />", 1, 150)' escape="trim" /><txp:evaluate query='string-length("<txp:body escape="tags" />" > 150)'>…</txp:evaluate>
<txp:permlink>Read more</txp:permlink>

TXP Builders – finely-crafted code, design and txp

Offline

#9 2023-02-19 10:07:38

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

Re: exclude article

Sorry, we need a s modifier here, to match multiline bodies:

<txp:hide process="1" trim="/^\s*(.{95}\w*)\b.+$/s" replace='$1... <txp:permlink>Read more</txp:permlink>'>
    <txp:body escape="tags" />
</txp:hide>

And thanks to Pat64 for the escape fix.

Online

#10 2023-02-19 14:36:11

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: exclude article

Thank you all for all suggestions,
But Jakob’s solution worked very well, million stars!
BTW: this is the best active forum for open source CMS.
I’m just 2 weeks with textpattern I learned a lot.

Here is final working title with working first 150 characters with read more:

<txp:article exclude="1" class="article-list"  limit="20" wraptag="ul" > 

    <h3><txp:title /></h3>

    <txp:evaluate query='substring("<txp:body escape="tags" />", 1, 150)' escape="trim" /><txp:evaluate    query='string-length("<txp:body escape="tags" />" > 150)'>…</txp:evaluate>
<txp:permlink>Read more</txp:permlink> <br>


          </txp:article>

Thank you all for your time and support.

Offline

#11 2023-02-20 06:51:36

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: exclude article

Note: the solution provided by etc is much better because the Regex in use doesn’t strip letters into the final word. A kind of good programming lesson as always.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#12 2023-02-20 20:38:10

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: exclude article

Thank you Pat64,
but I couldn’t use etc’s code . I got error
strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated while parsing form None on page xx

Offline

Board footer

Powered by FluxBB