Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2020-12-13 12:25:49

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

Re: [Solved] Displaying a random article but not the current one

Pat64 wrote #327462:

…And if I want to exclude all with empty cf_name?

<txp:article_custom section id cf_name exclude="id" limit="1" sort="rand()">
    <txp:title />
</txp:article_custom>

For the record, not simply inverses true/false parts output of <txp:else />. In no way it can be used for filtering.

Offline

#14 2020-12-13 12:50:41

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

Re: [Solved] Displaying a random article but not the current one

Yep.

Thank you lot Julian and Oleg (you’re the best)!
The above code works as expected (tested with 4.8.4).


Patrick.

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

Offline

#15 2020-12-13 15:44:48

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

Re: [Solved] Displaying a random article but not the current one

etc wrote #327463:

<txp:article_custom section id cf_name exclude="id" limit="1" sort="rand()">...

I feel like an idiot as I cannot understand how cf_name is excluded from this. Could someone please explain the code, so that we can be passing it on to related questions

This is as far. as I got:

one random article from an article_custom list generated from the current section which excludes the current id. I do not understand the id cf_name part of the tag.


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

Offline

#16 2020-12-13 17:11:55

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

Re: [Solved] Displaying a random article but not the current one

Maybe I misunderstood. But since 4.8.4 (see: https://github.com/textpattern/textpattern/blob/dev/HISTORY.txt#L21) short attributes fields (from the textpattern table) are available.

From this example: select section (the current one) id (articles but randomized) and cf_name (custom field name but only populated) and exclude id (current article one), finally, only one (limit="1").

Last edited by Pat64 (2020-12-13 17:19:32)


Patrick.

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

Offline

#17 2020-12-13 17:57:30

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

Re: [Solved] Displaying a random article but not the current one

I might have misunderstood too but why are articles with cf_name are excluded from this list? I would think that including cf_name, the article_custom would include not exclude those articles. Unless of course you actually did want to include them.


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

Offline

#18 2020-12-13 18:27:39

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

Re: [Solved] Displaying a random article but not the current one

Yannis.

If you turn your website into “debug” mode, the page source show us all the magic our Devs make each day with their intelligence:

<txp:article_custom section id epuise exclude="id, epuise" limit="1" sort="rand()">
    174,55 |     0,01 | 		<txp:article_custom section id epuise exclude="id, epuise" limit="1" sort="rand()">
    174,57 |          | 		</txp:article_custom>
    174,61 |     1,55 | 		[SQL: SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 AND `Posted` <= from_unixtime(2147483647) AND (Expires IS NULL OR from_unixtime(1608907599) <= Expires) AND ID NOT IN (5) AND Section  IN ('catalogue-general') AND Status IN (4,5) AND (NOT custom_3 != '')  ORDER BY rand() LIMIT 0, 1 ]
    176,16 |          | 		[Rows: 1]
    176,20 |          | 		[Article: '4']
    176,22 |          | 		[true]

SELECTAND (NOT custom_3 != '')

But you’re right. In my case, my custom_3 is empty for the attempted results I got!


Patrick.

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

Offline

#19 2020-12-13 18:57:08

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,075
Website Mastodon

Re: [Solved] Displaying a random article but not the current one

Pat64 wrote #327462:

My solution doesn’t work at all. I kept it here to show how I’m a bad TXP user.

what happened to your Cara TM website?


…. texted postive

Offline

Board footer

Powered by FluxBB