I have a comics website, http://www.hittingtreeswithsticks.com/, which I add new comics to each week. I’d like a newly posted comic to remain highlighted until 3 days after the post date.
So, here’s before:

Here’s desired:

I’m considering the following logic:
date in the database is currently set to datetime: 0000-00-00 00:00:00
PHP: Get date of comic with a date = $row[‘date’] url parameter:
echo '<ul>';
$imageCounter = 0;
while ($imageCounter < $imagesPerPage && ($row = $catResult->fetch_assoc())) {
echo '<li>';
echo '<span class="comics"><a href=".?action=viewimage&site='.$site. '&id=' . $row['id'] .'">
<img src="./scripts/thumber.php?date='. $row['date'] . '&img=.' . $thumbpath.$row['thumb'] . '&mw=220&mh=220"/></a>
<br /><br /> ' . $row['description'] . '</span>';
echo '</li>';
$imageCounter++;
}
echo '</ul>';
Then set datetime to that date…
$datetime1 = date_create($_GET['date']);
Now, I’d like to somehow set datetime2 = (datetime1 + 3 days)…
Then compare…
if ($datetime1 < $datetime2) {
set "comics" span class in CSS file to something else that would somehow highlight the newest post...
}
else {
set "comics" span class in CSS file to default
}
Is there an easier way to accomplish what I’m trying to do?
EDIT——————————–
I’m trying this now to highlight the newest comic for a period of 3 days… unfortunately, I’m struggling to figure out how to highlight just the latest comic instead of all of the comics if the condition is met.
//GET date
$desc = (isset($_GET['description']) ? ($_GET['description']) : null);
$row = $catResult->fetch_assoc();
$current_date = new DateTime;
echo "Current Date: " . $current_date->format('Y-m-d H:i:s');
echo "<br />";
$comic_date = new DateTime($row['date']);
echo "Comic Date: " . $comic_date->format('Y-m-d H:i:s');
$comic_date->modify('3 day');
//DISPLAY IMAGES TO CORRECT PAGE FROM DATABASE
echo '<ul>';
$imageCounter = 0;
while (($row['date'] < $current_date) && ($imageCounter < $imagesPerPage) && ($row = $catResult->fetch_assoc())) {
echo '<li>';
echo '<span class="comics"><a href=".?action=viewimage&site='.$site. '&id=' . $row['id'] .'">
<img src="./scripts/thumber.php?img=.' . $thumbpath.$row['thumb'] . '&mw=220&mh=220"/></a>
<br /><br /> ' . $row['description'] . $row['date'] . '</span>';
$imageCounter++;
echo '</li>';
}
if ($row['date'] >= $current_date) {
echo '<li>';
echo '<span class="newcomics"><a href=".?action=viewimage&site='.$site. '&id=' . $row['id'] .'">
<img src="./scripts/thumber.php?img=.' . $thumbpath.$row['thumb'] . '&mw=220&mh=220"/></a>
<br /><br /> ' . $row['description'] . $row['date'] . '</span>';
$imageCounter++;
echo '</li>';
}
echo '</ul>';
It is very easy to compare dates with DateTime.
Example how to modify and compare dates:
OR
You can do this with sql statement: