Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
txp:random - click for random article
Is a ‘random article link’ so easy to achieve (*) or why don’t we have a super performant txp:random
tag :-)
(*) <txp:article_custom sort="rand()" limit="1">
<!-- use txp:article for currently viewed section only -->
<p><txp:permlink><txp:title /></txp:permlink></p>
</txp:article_custom>
Is this the optimum or could a txp:random
tag be tuned for better performance?
- Seriously: Would it be possible to have a generic link which triggers the database to return a random article?
- Problem: I am thinking about cached full pages where the output from the code above would stay the same for the defined cache time.
- Of course the generic link must be excluded from the full page cache mechanism but this is something I can do in my cache software.
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: txp:random - click for random article
merz1 wrote:
Is this the optimum or could a txp:random tag be tuned for better performance?
Yes, it’s optimal. This is better to leave for plugin authors if you want an non-customizable, hard-coded solution which uses less resources — if that is what you are after. Or use block of PHP:
<txp:php>
$rs =
safe_row(
'ID,Title',
'textpattern',
'order by rand() limit 0,1'
);
echo '<a href="'.permlinkurl_id($rs['id']).'">'.$Title.'</a>';
</txp:php>
It is true that invoking article_custom() will fetch all column from textpattern table and calls the parser. But if you need an article, you also need to do all that. New tag would change nothing, just increase footprint.
Problem: I am thinking about cached full pages where the output from the code above would stay the same for the defined cache time.
Yes, because TXP’s cache is just modified-header. Nothing changes, because nothing is fetched by the browser. Only way to exclude a single block from a page when modified-header is used, is to not use it at all.
Last edited by Gocom (2010-08-16 14:37:26)
Offline
Re: txp:random - click for random article
Thanks Jukka!
- I could create an article (or a page) which contains the random PHP code
- Article gets a unique URL
- Unique URL is excluded from full page cache
- The random code calls, redirects to & delivers a random article back to browser
I think this would do it (generic link + ignoring full page cache).
Such a random function is great everywhere but I thought esp. about a photo portfolio where a random link pushes the motivation to explore more of the site compared to simple pagination.
A working solution would be a great How-To & TXPTip.
Edit: My quick notes above are too short :)
uses less resources — if that is what you are after
Yes, sure, but (one) main point is a URL which bypasses the full page caching.
article_custom() will fetch all column from textpattern table
Well, minimum for me for a ‘random article’ link would be article ID and URL. The use of the article title is already too much :)
Yes, because TXP’s cache is just modified-header. Nothing changes, because nothing is fetched by the browser.
a) I am using an external caching solution (which doesn’t matter I think)
b) As said above a generic URL would be great which calls the random code
c) Again: The random code calls, redirects to & delivers a random article back to browser
d) The random article can of course be cached
I don’t want to exclude a single block from a page!
Instead the link should always be the same.
The code behind the link is executed on the server side and not in the browser.
Does this make more sense?
Last edited by merz1 (2010-08-16 15:31:24)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline