Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
... show 10 randomly selected related articles
Is there a possibility to show 10 related articles that are picked from the database at random?
I thought along these lines:
txp:related_articles label=“The Possibly Related” limit=“10” sortby=“rand()” break=”<br />” wraptag=“p” labeltag=“p” /
However, txp:related_articles doesn’t seem to accept a “sortby” option.
The basic idea is: I may have several hundred related articles, but if people select one, they are only shown the ones that are chronologically closest (I think) and can therefore only move in cycles of articles which are, in a manner of speaking, related by category and chronology.
I’d like to remove the chronological aspect and just show 10 randomly selected articles that have the same category as the one that’s currently displayed.
If that’s not currently implemented, I guess I could just hack the code and modify the relevant sql statement along the lines “SELECT * FROM textpattern where Category1 = “whatever” ORDER BY RAND limit 10”. But before I start looking for the proper place in the Txp code, I thought I’d ask whether there was another way, or a plugin.
Thanks,
Offline
Re: ... show 10 randomly selected related articles
… got impatient. In case anyone wants to know: for a rough hack, change line 371 in taghandlers.php to:
“and Posted <= now() order by rand() limit 0,$limit”);
Offline
Re: ... show 10 randomly selected related articles
That’s rather good! It would be much nicer though methinks, if we could add a “sortby” attribute to this tag which could do this as per your example. :)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline