^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_comment_date()用法示例

get_comment_date( string $d = '',  int|WP_Comment $comment_ID )

Retrieve the comment date of the current comment.


描述


参数

$d

(string)
(Optional)
The format of the date. Default user’s setting.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Default value: ”

$comment_ID

(int|WP_Comment)
(Optional)
WP_Comment or ID of the comment for which to get the date. Default current comment.


返回值

(string) The comment’s date.


源代码

File: wp-includes/comment-template.php

function get_comment_date( $d = '', $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );
	if ( '' == $d )
		$date = mysql2date(get_option('date_format'), $comment->comment_date);
	else
		$date = mysql2date($d, $comment->comment_date);
	/**
	 * Filters the returned comment date.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $date    Formatted date string or Unix timestamp.
	 * @param string     $d       The format of the date.
	 * @param WP_Comment $comment The comment object.
	 */
	return apply_filters( 'get_comment_date', $date, $d, $comment );
}

更新日志

Version 描述
4.4.0 Added the ability for $comment_ID to also accept a WP_Comment object.
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    mysql2date()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    get_option()
  • wp-includes/comment-template.php:
    get_comment_date
  • wp-includes/comment.php:
    get_comment()

Used By

  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::column_date()
  • wp-includes/class-walker-comment.php:
    Walker_Comment::comment()
  • wp-includes/class-walker-comment.php:
    Walker_Comment::html5_comment()
  • wp-includes/comment-template.php:
    comment_date()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    
    $d = "l, F jS, Y";
    $comment_date = get_comment_date( $d, $comment_ID );
    echo $comment_date;
    
    // This will output something similar to "Saturday, November 6th, 2010". 
    
  2. Examples of Different Date Formats

    
    // Prints something like: Monday 8th of August 2005
    echo get_comment_date( 'l jS \of F Y' );
    
    // Prints something like: Mon Mar 8 2012
    echo get_comment_date( 'D M j Y' );
    
    // Prints something like 07/08/2017 (dd/mm/yyyy)
    echo get_comment_date( 'd\/m\/Y' );
    

    Display a beautiful, human-readable, comment time:

    
    function smk_get_comment_time( $comment_id = 0 ){
    	return sprintf( 
    		_x( '%s ago', 'Human-readable time', 'text-domain' ), 
    		human_time_diff( 
    			get_comment_date( 'U', $comment_id ), 
    			current_time( 'timestamp' ) 
    		) 
    	);
    }
    

    When called it will convert the time and return something like:

    "1 min ago", "3 mins ago", "17 hours ago", "7 days ago", "2 weeks ago", etc....

    Use this function because it’s more user friendly.

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈