通过使用以下代码,您可以使用get\\u the\\u date检查帖子是否在6个月前发布。
将下面的代码放在内容单一模板中,通知访问者他们正在阅读;“旧”;6个多月前发布的新闻。
# get last 6 month date from current date
$last_sixth_month_date = strtotime("-6 month");
# publish date
$post_poblish_date = strtotime( get_the_date() );
# get difference from two dates
$year1 = date(\'Y\', $last_sixth_month_date);
$year2 = date(\'Y\', $post_poblish_date);
$month1 = date(\'m\', $last_sixth_month_date);
$month2 = date(\'m\', $post_poblish_date);
$month_diffrence = (($year2 - $year1) * 12) + ($month2 - $month1);
if($month_diffrence < 0 )
{
# check difference between date is 6 or more than 6
if(abs($month_diffrence) >= 6 )
{
echo \'<span class="old-post"> 6+ months old </span> / \';
}
}