paulp - 09 May 2008 06:52 PM
I’m trying to figure out a way to post only one entry, which is randomly picked from the last three entries from a specific category. I have a feeling the answer is very simple, but I’m having a difficult time figuring this out.
I don’t think it is very simple. Can it be done? Of course. With built-in EE functionality? I don’t think so. We need some code, so let’s break out PHP:
<?php global $DB;
$query = 'SELECT * FROM `exp_weblog_titles`
LEFT JOIN `exp_weblog_data` ON exp_weblog_titles.entry_id = exp_weblog_data.entry_id
LEFT JOIN `exp_category_posts` ON exp_weblog_titles.entry_id = exp_category_posts.entry_id
WHERE cat_id = "127"
ORDER BY entry_date DESC LIMIT 3';
$entry_ids = $DB->query($query)->result;
$i = rand(0,2);
echo $entry_ids[$i]['entry_id'];
echo $entry_ids[$i]['title'];
echo $entry_ids[$i]['field_id_2'];
?>
That should get you started. Probably requires PHP 5, and you’ll have to adjust the cat_id and probably the output somewhat.