Get latest image updated time for gallery in nextgen gallery wordpress







Nextgen is a image slideshow and gallery plugin for wordpress and used in many website. Some time we need to get latest image updated time for nextgen gallery. Here is the function to do it.

<?php 
function album_update_time($id=1){
global $wpdb;
$gallery_info = $wpdb->get_results("SELECT * FROM wp_ngg_album WHERE id = $id");
$code = $gallery_info[0]->sortorder;
$y = unserialize($code);
$z = @implode(',' ,$y);

$gallery_results = $wpdb->get_results("SELECT  DISTINCT wp_ngg_pictures.imagedate as modified_date, galleryid FROM wp_ngg_gallery INNER JOIN wp_ngg_pictures ON wp_ngg_pictures.galleryid = wp_ngg_gallery.gid WHERE wp_ngg_gallery.gid IN (".$z.") ORDER BY wp_ngg_pictures.imagedate DESC limit 1");
$get_date = $gallery_results[0]->modified_date;

	if(empty($get_date)){
	$text = '<span id="no-updation" style="">We did not found any updations so far!!</span>';
	return $text;
	}

	$timezone = "Etc/Zulu";
	if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
	$d = date('d-m-Y H:i:s');
	//echo $d;
	
 $diff = strtotime($d) - strtotime($get_date)  ;
 $diff = abs($diff);
 $years = floor($diff / (365*60*60*24));
 $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
 $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
 $hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24) / (60*60));
 $minutes = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60) / (60));
 $seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60)); 
 
/* //printf("%d years, %d months, %d days,%d hours, %d minutesn", $years, $months, $days, $hours, $minutes); */
$ago='';
 if($years==0){
	 $ago = $months .' months ago.' ;
		if($months==0){
		$ago = $days .' days ago.' ;
			if($days==0){
			$ago = $hours .' hours ago.' ;
				if($hours==0){
				$ago = $minutes .' minutes ago.' ;
					if($minutes==0){
						$ago = $seconds . ' seconds ago';
							} elseif($minutes==1){
										$ago = $minutes .' minute ago.';
										} else {
										$ago = $minutes .' minutes ago.' ;
									}
								
							}
							elseif($hours==1){
							 
								$ago = $hours .' hour ago.';
									} else {
									$ago = $hours .' hours ago.' ;
								}
							}
					elseif($days==1){
						$ago = $days .' day ago.' ;
						} else{
						$ago = $days .' days ago.' ;
						}
				}
			elseif($months==1){
					
					$ago = $months .' month ago.' ;
					} else{
					$ago = $months .' months ago.' ;
					}
			}
	elseif($years==1){
	$ago = $years .' years ago.' ;
			
			$ago = $years .' year ago.' ;
			} else{
			$ago = $years .' years ago.' ;
			}
		
	return $ago;
}?>

Share With Friends

Speak Your Mind

*

Time limit is exhausted. Please reload CAPTCHA.