2011-04-02 54 views
2

更新我使用一些PHP顯示最後一次博客文章是使用get_the_timeget_the_modified_time功能WordPress的更新。但是,我不能得到的最後修改時間到段落內嵌顯示。顯示最後日期後在WordPress的

<?php 
     $x = get_the_time('U');    
     $m = get_the_modified_time('U');  
     if ($m != $x) { 
      $t = the_modified_time('F d, Y'); 
      echo "<p class=\"lastupdated\">Updated on $t </p>"; 
     } 
    ?> 

這裏的結果的截圖:

Screenshot

回答

2

the_modified_time打印最後修改時間,所以它打印它之前,您打印您的<p>

相反,你需要使用get_the_modified_time設置$t,就像這樣:

$t = get_the_modified_time('F d, Y'); 
0

這可能是因爲這些函數不返回的結果,而是直接echo它。因此,你必須在你需要他們當場給他們打電話。

0
 <?php 
      $x = get_the_time('U');    
      $m = get_the_modified_time('U');  
      if ($m != $x) { 
       echo "<p class=\"lastupdated\">Updated on ".the_modified_time('F d, Y')."</p>"; 
      } 
     ?> 
0

您也可以通過這個代碼,通過將其放置在循環的任意位置顯示文章的最後修改時間。

Posted on <?php the_time('F jS, Y') ?> 
<?php $u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if($u_modified_time != $u_time) { 
    echo "and last modified on "; 
    the_modified_time('F jS, Y'); 
    echo ". "; 
} ?>