2017-07-30 94 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