XF 1.2 Make notice order random

Hello Xenforo community,

I just bought a Xenforo license from my friend and am in control of a forum. We use notices system for showing advertisements, but there's one problem. The notices are not random, so the first ad is more popular than others.

Is there a way to make these notices show in random order? I can do some PHP, but I have no idea what to change, what kind of an addon to make etc.

Kind regards,


XenForo moderator
Staff member
Use the ad_ templates instead.

I have used this code in the past to randomise content:
<xen:set var="$var.1">

<xen:set var="$var.2">

<xen:set var="$var.3">

{xen:raw '$var.{xen:calc '({$serverTime} % 3) + 1'}'}
The 3 is the maximum number of items you want to randomise between.
Add a xen:set for each value.
Thank you Brogan for that example, but I am sorry: it did not suit my needs. So I went ahead and made the following script:


$con = mysqli_connect($config['db']['host'], $config['db']['username'], $config['db']['password'], $config['db']['dbname']);

if(mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: ".mysql_connect_error();

$query = "SELECT notice_id FROM xf_notice";

$result = mysqli_query($con, $query);

$i = 0;

while($row = mysqli_fetch_array($result)) {
   $noticeIds[$i] = $row['notice_id'];
   echo "Row is: ".$row['notice_id']."<br>";


for($i=0; $i < count($noticeIds); $i++) {
   echo "Notice id is: ".$noticeIds[$i]." and display order is: ".($i+1)."<br>";
   $query = "UPDATE xf_notice SET display_order = ".($i+1)." WHERE notice_id = ".$noticeIds[$i];
   mysqli_query($con, $query);
I know it's quite dirty (it's like a year since I've done PHP), but it rearranges the display order of all notices. It works fine, but the notice cache never gets rebuilt. Is there a way to rebuild the notice cache from outside Xenforo? How can I instantiate the necessary Xenforo classes in my own script? I know which function I need to call, but it is not static: I need to get my hands on the instance of XenForo_Model_Notice.
Last edited:
How didn't it suit your needs? What could the notice do that his example couldn't?
On my forum premium users can, for example, dismiss the ad by using the notice's dismiss button. That's why I wanted to stick to the in-built notices provided by Xenforo. Don't get me wrong, I still like the alternative approach he provided and I am sure I will find another use for it. I wasn't even aware of the ad_ templates before this.

There's also a chance that I understood it all wrong. Sorry if this is the case, I am going to use my fever as a lousy excuse.