I am trying to display a piece of content (image for now) that lasts 7 days, then changes to the next piece of content.
There are 6 piece of content I need to cycle through.. after the 7th day on content item #6. I need to start over at content item #1.
The general approach I am taking is, get a UNIX timestamp, and divide by 7 day, and modulus by the total content items.
I saw this as a suggestion but not clear what the $timestamp
is referring to?
$weeknumber = $ceil((time() – $starttimestamp) / 604800);
if ($weeknumber > {totalimages}) {
$ weeknumber = $weeknumber % {totalimages};
}
This (time() - $timestamp)
doesn't make sense to me
I'm expecting a return of 1-6 (or 0-5) and then do/load whatever based on that return value. I feel like I'm missing a part of it.
$unixStamp = time();
echo date('r', $unixStamp) . "<br />"; //outputs correct/current date
$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
echo "ARTICLE TO GRAB 1: ".$weekCount1;
echo '<br>';
$weekCount2 = (floor($unixStamp / 604800) % 6);
$weekCount2a = ($unixStamp / 604800) % 6;
$weekCount2b = (floor(time() - $unixStamp / 604800));
echo "ARTICLE TO GRAB 2: ".$weekCount2 .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2b .'<br>';
That being said, I'm also not clear on how I can TEST to ensure it will change/update correctly? (Do I temporarily add some days/weeks to the $unixStamp to force a different date?)
Another attempt and trying to get different values:
$unixStamp = time();
echo date('r', $unixStamp) . "<br /><br />"; //outputs correct/current date
$startDate = strtotime('2015-03-01 00:00:00');
$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6) + 1;
//$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6);
$weekCount2b = ($unixStamp / 604800) % 6;
$weekCount2c = (floor(time() - $unixStamp / 604800));
$weekCount2d = (ceil($unixStamp / 604800) % 6);
echo "ARTICLE TO GRAB 1: ".$weekCount1 .'<br>';
echo "ARTICLE TO GRAB 2a: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2b: ".$weekCount2b .'<br>';
echo "ARTICLE TO GRAB 2c: ".$weekCount2c .'<br>';
echo "ARTICLE TO GRAB 2d: ".$weekCount2d .'<br>';
I had added and changed a start date to subtract form the unixStamp, in order to get a time difference form when the rotqation is to start vs the unixStamp and trying to get a return for that. However, it never changes regardless of the start date?
Latest attempt: seems to update when I refresh though, instead of going off the startDate:
$unixStamp = time();
$startDate = strtotime('2015-02-1 00:00:00');
$weekCount = ceil($unixStamp - $startDate / 604800);
echo "CONTENT ID TO GRAB: ".$weekCount .'<br>';
if ($weekCount > 6) {
$weekCount = $weekCount % 6;
echo "CONTENT TO GRAB: ".$weekCount;
}