get_lastcommentmodified()获取时间点的最后评论发布时间

目录

描述

译文

最近一次评论修改日期。设置$cache_lastcommentmodified参数后,该函数可从缓存中返回值而不必进入数据库。

原文

The date the last comment was modified. If $cache_lastcommentmodified is set this function returns its value from the cache without hitting the database.

get_lastcommentmodified() 描述

用法

<?php get_lastcommentmodified$timezone ?>

get_lastcommentmodified() 用法

参数

$timezone

(string) (可选) Which timezone to use in reference to 'gmt', 'blog', or 'server' locations.

默认值: 'server'

get_lastcommentmodified() 参数

返回值

(string) 

Last comment modified date as a MySQL DATETIME.

get_lastcommentmodified() 返回值

注意

  • 使用到: $wpdb to read from the comments table.
  • 使用到 global: array $cache_lastcommentmodified

get_lastcommentmodified() 注意

历史

添加于 版本: 1.5.0

get_lastcommentmodified() 历史

源文件

get_lastcommentmodified() 函数的代码位于 wp-includes/comment.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * The date the last comment was modified.
 *
 * @since 1.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 * @staticvar array $cache_lastcommentmodified
 *
 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog',
 *		or 'server' locations.
 * @return string Last comment modified date.
 */
function get_lastcommentmodified($timezone = 'server') {
	global $wpdb;
	static $cache_lastcommentmodified = array();

	if ( isset($cache_lastcommentmodified[$timezone]) )
		return $cache_lastcommentmodified[$timezone];

	$add_seconds_server = date('Z');

	switch ( strtolower($timezone)) {
		case 'gmt':
			$lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
			break;
		case 'blog':
			$lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
			break;
		case 'server':
			$lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server));
			break;
	}

	$cache_lastcommentmodified[$timezone] = $lastcommentmodified;

	return $lastcommentmodified;
}

get_lastcommentmodified() 源文件