a random post on main page?

Post Reply
ntsu
Jr. Bludit
Posts: 7
Joined: Sat Aug 24, 2019 3:46 pm

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!
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
ntsu
Jr. Bludit
Posts: 7
Joined: Sat Aug 24, 2019 3:46 pm

I saw it, but somehow it did not work!
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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();
	}
}

?>
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
ntsu
Jr. Bludit
Posts: 7
Joined: Sat Aug 24, 2019 3:46 pm

thats great! thank you very much!!
Post Reply