2017-07-30 40 views
-2

我在我的wp主頁中創建了一個帖子循環,其中5個最近的帖子被一個在另一個之下顯示。 循環WP數據的代碼Wordpress get_the_date()只檢索帖子ID

$args = array('numberposts'=>'5'); 
$recentposts = wp_get_recent_posts($args); 
foreach($recentposts as $post){ 
    $v = $post['ID']; 
    echo 'Title:'.get_the_title($v).'<br>'; 
    echo 'Date:' .get_the_date($v).'<br>'; 
} 

標題部分作品完美,但日期部分只顯示後,沒有任何其他的ID。

我在做什麼錯?

+0

始終嘗試檢查函數引用以查看它所需的參數:-https://developer.wordpress.org/reference/functions/get _the_date/ –

回答

5

看的文檔:https://codex.wordpress.org/Function_Reference/get_the_date

首先參數是格式,二是ID,那麼:

// whatever your format 
get_the_date('Y-m-d', $v) 

爲了讓您的默認的WordPress網站的日期格式:

$date_format = get_option('date_format'); 
get_the_date($date_format, $post_id); 
+0

好的。這很有用,謝謝。 – Aditya

-1
while (have_posts()) : the_post(); 
    <li class="icon-date"><?php echo get_the_date('Y-m-d'); ?></li> 
    <li class="icon-time"><?php the_time('H:i:s'); ?></li> 
+0

你應該包括一些關於爲什麼這是正確的答案。 – Difster