There is another easy solution for one single random post:
- Code: Select all
$category = "1,2,3";
$number = "1";
$skip = mt_rand(1,100);
$template = "MyTemplate1";
include 'cms/show_news.php';
Now it will sort all your news in pages, each post will have a page
for itself (because $number = "1"), and using the $skip you can choose
which page-post you will show, so we make it random!
Using the my_rand php function:
The first number (in the example 1) is the lowest number for the random
to choose, for us, start from page/post 1
The second number is the highest number to random, for us, the oldest post
So we make a random between the numbers that we want
and it will show you a random post (just check that you have enough
posts for the numbers you choose)!
You can also make $number = "2";
Then it will show two posts per page (or more if you wish)
but these posts will be (by date) one after the other, not so bad
If you wish to random 2 or more posts, you can add a $sort to
try and make them not one after the other!
For example:
- Code: Select all
$category = "1,2,3";
$number = "1";
$skip = mt_rand(1,100);
$sort = array('short', 'asc');
$template = "MyTemplate1";
include 'cms/show_news.php';
This will sort all the news by the number of signs in the short story!
Pretty random I'de say, plus you can also use one of the following:
- Code: Select all
$sort = array('full', 'asc');
$sort = array('views', 'asc');
$sort = array('title', 'asc');
$sort = array('comments', 'asc');
Hope it helps,
DarkSlim