我有一个问题。 如何在PHP中显示文本4天?
示例:我今天写了一篇文章,我希望在4天内显示“新”,并在此之后隐藏它。
非常感谢。
答案 0 :(得分:0)
这不是特定于WordPress的,您需要删除foreach
循环以供实际使用..但它应该让您了解如何比较相对日期:
<?php
$sample_dates = array(
'2011-02-17',
'2011-02-18',
'2011-02-19',
'2011-02-20',
'2011-02-21',
'2011-02-22',
'2011-02-23'
);
$post_date = '2011-02-17';
foreach ($sample_dates as $date_today) {
echo '<p>If today is ' . $date_today . ', the post from ' . $post_date . ' is: ';
if (strtotime('+4 days',strtotime($post_date)) >= strtotime($date_today)) {
echo 'NEW';
} else {
echo 'OLD';
}
echo '</p>' . PHP_EOL;
}
?>