Reputation: 4306
I have a function that returns a certain date format in a foreach loop. This is how it looks.
Wed 17-05
Thu 18-05
Fri 19-05
Sat 20-05
Sun 21-05
As you can see the current day appears in the middle. This is my code:
for ($i = 2; $i > -3; $i--)
{
echo '<li>'.date('D d-m', strtotime($i . ' days ago')) . '</li>'.'<br />';
}
what i want to achieve is, i want to give the middle day a special color. example:
Wed 17-05
Thu 18-05
Fri 19-05
Sat 20-05
Sun 21-05
All the days appear in an <li>
can i get the middle day to appear in an li with a distinct class so i can style it in my css?
Upvotes: 0
Views: 105
Reputation: 12085
use date('D d-m') if the date is current date echo add the class="distinct"
<?php
for ($i = 2; $i > -3; $i--)
{
$class="";
if(date('D d-m')==date('D d-m', strtotime($i . ' days ago')))
{
$class=' calss="distinct"';
}
echo '<li'.$class.'>'.date('D d-m', strtotime($i . ' days ago')) . '</li>'.'<br />';
}
?>
Upvotes: 1
Reputation: 1
for ($i = 2; $i > -3; $i--)
{
if($i == 0){
$active = 'active';
}
echo '<li class=".$active.">'.date('D d-m', strtotime($i . ' days ago')) . '</li>'.'<br />';
}
Write a class in your css, is ok?
Upvotes: 0