Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-03-21 19:02:02

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Request: Daily random article

I need a way to output a random article that changes daily (or even any given interval).

Don’t know enough php to do this, but I’ve successfully use greenrift’s rotating image plugin that performs the same function for an image from a given category on a daily, weekly or Yearly basis.

Offline

#2 2006-03-21 19:31:53

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Request: Daily random article

Can that not de done allready, using TXP’s sortby attribute, sortby=“random”?
I’ve seen that article custom accepts this value, as of tEXTBOOK,
not sure about the normal article tag though,

regards


⌃ ⇧ < ⌃ ⇧ >

Offline

#3 2006-03-21 20:06:21

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Request: Daily random article

marios wrote:

Can that not de done allready, using TXP’s sortby attribute, sortby=“random”

Thanks for the reply, but you can’t do it that way. The attribute sortby=“rand()” will output a random article on a per-page-load basis.

Offline

#4 2006-03-22 04:11:55

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: Request: Daily random article

mrdale,

In order to accomplish a feature like that you will have to store data some where (db or file). My first thought would be something like:
1) Write a script that will randomly select an article id from the TXP db and write it to a file or db
2) Create a plugin that will access that file or db and grab the article id from the file and will then display that article
3) Setup a cron job to run the script from #1 everyday at midnight so you can rewrite the article id in the file

If you wanted to do it all in the plugin, you could easily do that but I think you’ll end doing unecessary checks, but I’m not positive how that will impact performance. This way may seem the better choice if you want easier control over the interval.

Let me know if that helps you out.

Offline

#5 2006-03-22 09:00:06

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Request: Daily random article

It can be achieved without storing data. You can round time() to the precision of a day, and then hash that value onto the set of available article-ids.
Could be done with at most two small, compact queries, that would be cached by mysql’s query cache, at least for mysql 4.0 and up.

Offline

#6 2006-03-23 19:49:06

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Request: Daily random article

I thought about this some more. If I were mr.php then I’d make a function that would…
  1. get the php date(z) function, then…
  2. get an attribute of idrange=“startArticleID,endArticleID”
  3. figure out a way to assign a unique article ID based on day of the year (even though the article range would probably never equal exactly 365(6)

Any PHP-guru want to be a hero (wish I could do it myself actually)?

Offline

#7 2006-05-02 19:56:01

baby
Plugin Author
From: Buenos Aires, Argentina
Registered: 2005-10-16
Posts: 95
Website

Re: Request: Daily random article

Hi,

I’m by no means a PHP hero, but a teacher and I’ve set up as a semester assignment for last year non-university students to create a nice plugin for txp.

I wanted to use a PHP open source project as the basis and txp showed up as the most interesting since it is:
  • quite stable
  • very well documented (for an open source project, at least) both in the user side and in the developer side
  • nicely prepared for user-contributed code

Since this request doesn’t seem too hard and it’s probably only client-side, I’ll probably assign it to a group of two or three students to develop. I’ll obviously post here the resulting plugin.

However, don’t hold your breath, since the semester ends by late July, and I don’t expect much code available before that…


Mariano AbsatzEl Baby

I don’t suffer from insanity. I enjoy every minute of it.

Offline

#8 2006-05-02 21:16:13

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Request: Daily random article

Thanks Mariano,

Sounds promising.

Offline

#9 2006-05-24 11:52:48

1ukaz
Archived Plugin Author
From: Buenos Aires, Argentina
Registered: 2006-05-05
Posts: 17

Re: Request: Daily random article

Hi mrdale; I wrote this plugin that maybe could help you…..
All you have to do to run this plugin is make sure the files directory that txp uses for storing uploaded files from the users is created on, and your web server has writing permissions on it; this is since this plugin will create and use a random.txt file in that directory; don´t worry is not a security issue.
The plugin can rotate from the server side an article every hour/day/week/month/year; by default is day but to change it just pass <code>rotate=“wharever”</code> param to the tag.
You can see more at the help topic on plugins list once installed

See at MY (1ukaz) post below to download the latest version which have been added:
  1. category
  2. section
  3. author

Last edited by 1ukaz (2006-05-31 17:55:14)

Offline

#10 2006-05-24 14:56:23

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Request: Daily random article

Thanks Lucas,

I’m looking forward to using this plugin, but I can’t get it to work.

I’m calling it like this:

<lhg_article_rotate form="article-sidebar" />

Also, is this plugin category aware?

Last edited by mrdale (2006-05-24 15:09:07)

Offline

#11 2006-05-26 12:22:51

1ukaz
Archived Plugin Author
From: Buenos Aires, Argentina
Registered: 2006-05-05
Posts: 17

Re: Request: Daily random article

Hi mrdale; the way you are calling the plugin is correct; perhaps the form name brings trouble; perhaps doesn’t like the “-”. Try it with another form to see if is that the problem……
Otherwise make sure the files directory that txp usues outside /textpattern/ for storing the files uploaded by the users exists and your web server has writing permissions, since the plugin need that folder.
Another thing is, the plugin doesn’t work and there is no message from txp??? Try changing the status of txp to debugging or testing and try out the plugin and tell me the message ……
Let´s keep in touch; you can always e-mail me of course …..
One more thing: I don`t understand what you mean with “is this plugin category aware?”
Want to explain me?? Sorry for my english …….

See ya.

Offline

#12 2006-05-26 15:58:54

Rigel
Member
From: España
Registered: 2005-09-02
Posts: 99
Website

Re: Request: Daily random article

mrdalem, the correct code is <txp:lhg_article_rotate form="article-sidebar" />

Thanks 1ukaz for the plugin

Last edited by Rigel (2006-05-26 19:05:03)

Offline

Board footer

Powered by FluxBB