Hi!
You should first scrap that idea, cause it generates more pain that it solves. The entrypaging plugin only specifies you with the link. To get the contents of that entry, you need PHP logic.
I'd go a seperate route, and either create a custom event plugin that does your job, or implement it inside your template. Since putting it into your template's config.inc.php is a lot easier, I will tell you how to use that variant.
1. Inside your config.inc.php file (if it does not exist, create it) add this code:
Code: Select all
function show_random_entry($params, &$smarty) {
global $serendipity;
// Check latest timestamp
$ts = serendipity_db_query("SELECT MAX(timestamp) AS max FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false'");
// If the latest entry is older than 2 days...
if (is_array($ts) && $ts[0]['max'] <= time()-(86400*2)) {
// Get a random entry
$random_entry = serendipity_db_query("SELECT id FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' ORDER BY RAND() LIMIT 1");
if (is_array($random_entry) && isset($random_entry[0]['id'])) {
$old_entries = $smarty->get_template_vars('entries');
$smarty->assign('is_random_entry', true);
$entry = array(serendipity_fetchEntry('id', $random_entry[0]['id']));
serendipity_printEntries($entry, false, false, 'ENTRIES2', false, true, false);
$out = serendipity_smarty_fetch('smarty_random_entry', 'entries.tpl');
$smarty->assign('entries', $old_entries);
return $out;
}
}
}
$serendipity['smarty']->register_function('show_random_entry', 'show_random_entry');
That is a function that does your logic. As you can see, this is not really trivial, you first need to get the most recent entry timestamp, then compare it to the current time, then use the s9y API to fetch and display the entries.
2. Inside your entries.tpl file you can add this on top of the file:
Code: Select all
{if !$is_random_entry}
{show_random_entry}
{/if}
3. The actual entry is then printed using the entries.tpl file itself. You can add {if $is_random_entry} checks in there to make custom outputs when the random entry is showed, or {if !$is_random_entry} checks to only show things when NOT in random entry mode (like currently the footer will shown twice in the page, you would need to wrap the footer output {if !$is_random_entry} ... {/if} around there, if you don't want it for a random entry.
Regards,
Garvin