Page 1 of 1

a random post on main page?

Posted: Sat Aug 24, 2019 3:48 pm
by ntsu
hello,

i'm trying to show a random post on the home page each time i refresh. is that possible in a way? :| i would be thankful for any help. thanks alot!

Re: a random post on main page?

Posted: Sat Aug 24, 2019 3:52 pm
by Edi
There is a thread about it:

Page static with random

Perhaps the code has to be adapted a little bit for Bludit 3.9.2.

Re: a random post on main page?

Posted: Sat Aug 24, 2019 3:59 pm
by ntsu
I saw it, but somehow it did not work!

Re: a random post on main page?

Posted: Mon Aug 26, 2019 11:51 am
by Edi
There are some changes. You can use the following:

Code: Select all

<?php

global $pages;

$onlyPublished = true;
$pageNumber = 1;

$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);

$random_key=array_rand($publishedPages);

$random_content = $publishedPages[$random_key];

foreach ($publishedPages as $pageKey){
	if ($pageKey == $random_content ) {
        $page = new Page($pageKey);
		echo $page->title();
		echo $page->permalink();
		echo $page->content();
	}
}

?>

Re: a random post on main page?

Posted: Fri Aug 30, 2019 11:25 pm
by ntsu
thats great! thank you very much!!