Forum Moderators: mack

Message Too Old, No Replies

How to rotate ads by time in a single category?

         

Yekta20

3:48 pm on Dec 1, 2024 (gmt 0)



function getRotatingOrder($items_count = 5) {
// Calculate the number of hours since the start time
$hours = floor(time() / 3600);

// Calculate the number of rotations
$rotation = $hours % $items_count;

// Create ORDER BY expression for SQL
$orderBy = "ORDER BY CASE
WHEN (id % {$items_count}) = {$rotation} THEN 0
WHEN (id % {$items_count}) > {$rotation} THEN (id % {$items_count})
ELSE (id % {$items_count} + {$items_count})
END ASC, date_added DESC";

return $orderBy;
}
$order_by = getRotatingOrder(10); // rotation for 10 ads
Hello, I have an advertising site.

It consists of 2 categories.

The code I shared loops the ads.

However, it loops the ads in 2 categories.

I want it to loop only in one category.

I also want all the ads to loop in the 1st category without specifying the number of ads.

Category 1 should loop in this category.

Category 2 should not loop in this category.