如何在 Wordpress 中格式化发布日期? [英] How do I format the post date in Wordpress?

查看:40
本文介绍了如何在 Wordpress 中格式化发布日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a sidebar where I want to show the most recent posts. Right now it shows the title, date, and an excerpt. The date shows the time which I want to get rid of. I show the date using this: $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 而没有时间.提前致谢.

It shows the date like this: 2013-08-11 18:29:04 and I would like it like this 8-11-2013 and without the time. Thanks in advance.

推荐答案

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

这会按照您想要的方式对其进行格式化.只需用它替换循环中的 $recent['post_date'].

This formats it the way you want. Just replace the $recent['post_date'] in your loop with that.

这篇关于如何在 Wordpress 中格式化发布日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆