如何在 WordPress 中设置发布日期的格式?

2024-05-22

我有一个侧边栏,我想在其中显示最新的帖子。现在它显示标题、日期和摘录。日期显示了我想要删除的时间。我用这个显示日期: $recent["post_date"]

 <?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    echo '<li id="sidebar_text"><b>'.$recent["post_title"].'</b></li><li style="font-size:12px">'.$recent["post_date"].'</li><li><i style="font-size:15px">'.$recent["post_excerpt"].'</i><a href="'.get_permalink($recent["ID"]).'"> Read   More</a></li>';
     }
 ?>

它显示的日期如下:2013-08-11 18:29:04,我希望像这样 8-11-2013 并且没有时间。提前致谢。


date('n-j-Y', strtotime($recent['post_date']));

这将按照您想要的方式格式化它。只需更换$recent['post_date']在你的循环中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 WordPress 中设置发布日期的格式? 的相关文章

随机推荐