• Về tôi
  • Chính sách riêng tư
  • Liên hệ

HoangThuc.com

Website Developer

  • Trang chủ
  • WordPress
    • Plugin wordpress
  • Lập trình
    • Php
  • Thủ thuật máy tính
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

Bài viết khác

  • Sử dụng media của wordpress để tải hình ảnhSử dụng media của wordpress để tải hình ảnh
  • Tạo template trong plugin wordpressTạo template trong plugin wordpress
  • Xóa slug trên custom post và custom taxonomy: Phần 2Xóa slug trên custom post và custom taxonomy: Phần 2
  • Xóa slug trên custom post và custom taxonomy: Phần 1Xóa slug trên custom post và custom taxonomy: Phần 1
  • Plugin lấy tin tự động version 2.1Plugin lấy tin tự động version 2.1
  • Lỗi redirect khi phân trang trong single wordpressLỗi redirect khi phân trang trong single wordpress
Share

Bình luận

Bình luận

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

Bài viết mới

> 2021/10/11 19:10:10 [INFO] acme: Registering account for admin@X.X.X.X>

  • Dữ liệu JSON trong MySQL
  • Chuyển thư mục public sang public_html trong Laravel khi deploy
  • Fix “Requested icu-uc 50.1 but version of icu-uc is” trên DirectAdmin

FOLLOW ME

  • Facebook
  • Google+
  • Twitter

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 © 2022 · HoangThuc.com · Genesis Framework