I’m trying to add a class to an HTML tag depending on the date of the WordPress post. So far I have the code:
while ($recentPosts -> have_posts()) :
$recentPosts -> the_post();
if (strtotime(the_date('', '', '', false)) > strtotime('-14 days')) {
echo '<h5 class="new">';
}
else {
echo '<h5>';
}
the_date();
endwhile;
The class is working great, but the problem I’m having is that the date will not show up after the h5 tag. Not sure what I’m missing or doing wrong.
Phil
The problem seems to be that you’re calling
the_date()twice… try usingget_the_date($postId)or storingthe_date()on your line 2.