Wordpress在循环LOOP中获取 post_date 使用自定义日期时间格式

code示例:

<?php $args = array('numberposts' => '16','category' => '8');
	  $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
	  foreach ($recent_posts as $recent) {
	  	echo '<li><a href="'. get_permalink($recent["ID"]).'">'.$recent["post_title"].'</a><span class="list-meta">'. mysql2date('Y-m-d', $recent["post_date"]) .'</span></li>';
	  }
?>

原本直接用$recent['post_date']输出的是 2014-11-11 14:30:24 这样的格式,但现在不需要时间的输出,Y.Cheung 只需要输出日期,找了一下用mysql2date函数就可以。

参考: https://codex.wordpress.org/Function_Reference/mysql2date

Y Cheung

Y Cheung

Blogger, Programer & Traveler.
Shanghai