2011-02-22 23 views

回答

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; 
    } 
?> 
相關問題