Hi You, I am Tade

You are here: Home / Wordpress / Wordpress nâng cao / Hiển thị thời gian kể từ ngày đăng trong wordpress

Hiển thị thời gian kể từ ngày đăng trong wordpress

22 May, 2016 by Hoàng Thức

Đây là một đoạn code nhỏ trong wordpress cho phép bạn hiển thị thời gian từ ngày đăng bài đến hiện tại. Các bạn có thể thêm nó vào file function.php


/**
 * Display time since post was published
 *
 * @uses	human_time_diff()  Return time difference in easy to read format
 * @uses	get_the_time()  Get the time the post was published
 * @uses	current_time()  Get the current time
 *
 * @return	string  Timestamp since post was published
 *
 * @author c.bavota
 */
function get_time_since_posted() {

	$time_since_posted = human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ago';

	return $time_since_posted;

}

Bây giờ các bạn có thể sử dụng hàm get_time_since_posted() để hiển thị thời gian từ ngày đăng bài cho đến hiện tại trong loop wordpress.
Tham khảo hàm human_time_diff() tại http://codex.wordpress.org/Function_Reference/human_time_diff

Filed Under: Wordpress, Wordpress nâng cao Tagged With: Thủ thuật wordpress, wordpress nâng cao

  • Home
  • About
  • Donate

Danh mục

  • Blog
  • Lập trình
  • Laravel
  • MYSQL
  • Php
  • Thủ thuật máy tính
  • Vps
    • DirectAdmin
  • Wordpress
    • Plugin wordpress
    • Wordpress căn bản
    • Wordpress nâng cao
      • Custom post wordpress

Archives

  • October 2021
  • January 2021
  • December 2020
  • November 2020
  • September 2020
  • August 2020
  • September 2019
  • August 2019
  • July 2019
  • June 2018
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • March 2017
  • November 2016
  • September 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • January 2016
  • December 2015
  • May 2015
  • April 2015
Copyright © 2023 · HoangThuc.com · Genesis Framework