Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-11-10 21:35:13

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Select a list of articles by id..

Hi TXP’ers,
been working for a couple of years with TXP but this is the first time I can’t get around something.
For my site I want to select a list of articles by id and display randomly one of them.

Something like tis: <txp:article_custom form=“formname limit=“1” sortby=“rand()” id=“3,7,10,11,13” />

Is this possible?
Would be really neat and cool if this is possible.
Thanks all.

Offline

#2 2009-11-10 21:43:03

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Select a list of articles by id..

Yes, it is.

In fact, your code would almost work if you properly close the quotes after “formname” and change “sortby” by just “sort”.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2009-11-10 21:52:29

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

maniqui wrote:

In fact, your code would almost work if you properly close the quotes after “formname” and change “sortby” by just “sort”.

Sorry, made a typo there.
I tried the code I posted but TXP always gives me the content of the first ID from that list of ID’s.

Last edited by karl.dvx (2009-11-10 21:53:01)

Offline

#4 2009-11-10 23:50:41

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Select a list of articles by id..

<txp:article_custom form="formname" limit="1" sort="rand()" id="3,7,10,11,13" />

works

Last edited by MattD (2009-11-10 23:51:05)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2009-11-11 00:07:41

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

Yes, it works indeed.

But the problem is I always get the same article on every page, the first one (3).
When I go to another page I want to get the content of another article ID, one of those selected in the list.. But that’s not the case.

Offline

#6 2009-11-11 00:09:11

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Select a list of articles by id..

Interesting, I put this on a test page and got a different article every time I refreshed the page.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#7 2009-11-11 00:18:41

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

Really strange, I tried the exact code with correct formname from above on two sites but always get the same page. Just don’t get it..
Thanks for your help.

Offline

#8 2009-11-11 00:34:46

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

What the…
Tried it on a fresh install in MAMP, all works fine. But it won’t work on my site..
Maybe because of a plugin? I only use two front-end plugins (mem_article_count and zem_link).
THIS IS MADNEEEESS

Offline

#9 2009-11-11 00:41:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: Select a list of articles by id..

Is your browser/server cacheing the results somewhere? Try setting the send last modified header in Advanced Prefs to no and see if it makes any difference.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2009-11-11 00:51:48

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

Bloke wrote:

Is your browser/server cacheing the results somewhere? Try setting the send last modified header in Advanced Prefs to no and see if it makes any difference.

Tried it. But still get the same result on this PC, iPhone and another PC.
I see my host disabled some PHP functions -> proc_get_status, proc_nice, proc_terminate, pcntl_exec are disabled on my hosting.
Maybe this could be the reason?

Offline

#11 2009-11-11 01:24:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Select a list of articles by id..

karl.dvx wrote:

Maybe this could be the reason?

Please post your high diagnostics. (Admin > Diag > High). Likely it’s MySQL version issue (too old).

Alternatively you could use PHP to output an random article.

<txp:article_custom limit="1" id='<txp:php> $id = array(3,7,10,11,13); echo $id[rand(0,4)]; </txp:php>' />

Offline

#12 2009-11-11 02:52:51

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: Select a list of articles by id..

Code sample above doesn’t work either, too bad.

Diagnostics:
MySQL: 5.0.67
PHP versie: 5.2.8

I guess the problem is my hosting. On a local version in MAMP everything works fine.
I now assign an extra category to the articles I want to select.. Not the best solution but it works.
Thanks for your time every one of you.

Offline

Board footer

Powered by FluxBB