我在我的wp主页上创建了一个帖子循环,其中5个最近的帖子一个在另一个下面显示.循环wp数据的代码是
$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>';
}
Run Code Online (Sandbox Code Playgroud)
"标题"部分工作正常,但"日期"部分仅显示帖子的ID,而不显示任何其他内容.
我究竟做错了什么?
查看文档:https://codex.wordpress.org/Function_Reference/get_the_date
第一个参数是格式,第二个是ID,所以:
// whatever your format
get_the_date('Y-m-d', $v)
Run Code Online (Sandbox Code Playgroud)
要获取默认的Wordpress站点日期格式:
$date_format = get_option( 'date_format' );
get_the_date( $date_format, $post_id );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1578 次 |
| 最近记录: |