How do I format the post date in Wordpress?

前端 未结 4 1702
执笔经年
执笔经年 2021-02-05 08:27

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 d

相关标签:
4条回答
  • 2021-02-05 08:58
    date('n-j-Y', strtotime($recent['post_date']));
    

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

    0 讨论(0)
  • 2021-02-05 08:58

    Whilst Syfaro's answer is correct, best practice is to use WordPress's own function for this.

    get_the_date

    This defaults to the format set in the WordPress admin settings (Settings -> General), so gives a more accessible solution for future editing - particularly useful if you roll your code in multiple sites, or more importantly if you release it publicly.

    Also, don't forget to escape output - check out esc_html and esc_html_e

    0 讨论(0)
  • 2021-02-05 09:01
    date_i18n('l d/m/Y \à\s g:i', strtotime($item['time']))
    
    0 讨论(0)
  • 2021-02-05 09:03

    Replace $recent["post_date"] with mysql2date('n-j-Y', $recent['post_date']).

    0 讨论(0)
提交回复
热议问题