Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2020-12-12 11:53:28
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
[Solved] Displaying a random article but not the current one
Hi TXPexperts! 😍
Because my client do not need categories, currently, I’m using with some good results in order to simulate related_article
😜:
<txp:variable name="ID" value='<txp:article_id />' />
<txp:article_custom section='<txp:section />' limit="1" sort="rand()">
<txp:evaluate query='contains(<txp:variable name="ID" />,<txp:article_id />)'><txp:else />
<txp:title />
</txp:evaluate>
</txp:article_custom>
I wonder if there is a kind of negative attribute in order to simplify my purpose (i.e. not='<txp:article_id />'
)?
Please, don’t blame me if I’m not clever: I just discover this very useful <txp:article />
tag! 😁
Last edited by Pat64 (2020-12-13 12:51:07)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#2 2020-12-12 12:54:42
- etc
- Developer
- Registered: 2010-11-11
- Posts: 4,051
- Website
Re: [Solved] Displaying a random article but not the current one
Hi Patrick,
there are many solutions, the most straightforward is to use empty match
attribute:
<txp:related_articles section match="" limit="1" sort="rand()">
<txp:title />
</txp:related_articles>
Offline
#3 2020-12-12 12:55:57
- jakob
- Admin
- From: Germany
- Registered: 2005-01-20
- Posts: 4,026
- Website
Re: [Solved] Displaying a random article but not the current one
Pat64 wrote #327434:
I wonder if there is a kind of negative attribute in order to simplify my purpose…
Hi PatTXPexpert 😄
There is! It’s called exclude
. See the attribute description in the docs. You should be able to do:
<txp:article_custom section='<txp:section />' exclude='<txp:article_id />' limit="1" sort="rand()">
<txp:title />
</txp:article_custom>
TXP Builders – finely-crafted code, design and txp
Offline
#4 2020-12-12 13:07:35
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
Re: [Solved] Displaying a random article but not the current one
My bad!
Obviously, Julian, there is an exclude
attribute…
But, sorry, I prefer Oleg’s solution 😜
(in use, with some good results, here: https://editions-du-26-octobre.com/catalogue-general/le-collage-paul-alexis)
Last edited by Pat64 (2020-12-12 13:17:33)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#5 2020-12-12 13:12:52
- etc
- Developer
- Registered: 2010-11-11
- Posts: 4,051
- Website
Re: [Solved] Displaying a random article but not the current one
Pat64 wrote #327437:
I prefer Oleg’s solution 😜
Internally it is mapped to Jacob’s one :-)
Will be even more straightforward in 4.8.5:
<txp:related_articles match="section" limit="1" sort="rand()">
<txp:title />
</txp:related_articles>
Offline
#6 2020-12-12 13:18:09
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
Re: [Solved] Displaying a random article but not the current one
Cool, Thanks !
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#7 2020-12-13 07:12:44
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
Re: [Solved] Displaying a random article but not the current one
Oleg:
Is there a way to filter the results by empty custom field (or negative)?
We can’t add this attribute custom_field_name="%"
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#8 2020-12-13 08:40:58
- colak
- Admin
- From: Cyprus
- Registered: 2004-11-20
- Posts: 8,451
- Website
Re: [Solved] Displaying a random article but not the current one
Would this help?
<txp:related_articles match="section" limit="1" sort="rand()">
<txp:if_custom_field name="name" not>
<txp:if_custom_field name="name2" not>
<txp:if_custom_field name="name3" not>
<txp:if_custom_field name="name4" not>
<txp:if_custom_field name="name5" not>
<txp:title />
</txp:if_custom_field>
</txp:if_custom_field>
</txp:if_custom_field>
</txp:if_custom_field>
</txp:if_custom_field>
</txp:related_articles>
Edited to add that it would be nice if a comma separated list of CF names could be supported. Something like… <txp:if_custom_field name="name,name2,name_etc" not>
Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.
Offline
#9 2020-12-13 08:53:59
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
Re: [Solved] Displaying a random article but not the current one
Thank you Yiannis.
But, unfortunately, sometimes we got no results (matching custom fields are omitted)…
Just to notice: my first error comes with the official document where “related articles tag is used to produce a list of related (by category) articles” but in fact it is more flexible (see: https://docs.textpattern.com/tags/related_articles)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#10 2020-12-13 09:07:31
- Pat64
- Plugin Author
- From: France
- Registered: 2005-12-12
- Posts: 1,453
- Website
Re: [Solved] Displaying a random article but not the current one
Ok.
Based both on etc
and colak
help, I’m using this:
match=", not %my_custom_field%"
It seems to work as expected. But, now I need some Dev’s expertise: is it good or… bad? 🤨
Who’s bad
— Michael Jackson.
Last edited by Pat64 (2020-12-13 09:13:07)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline