Implementing Jquery Timeago Using PHP.
💻 coding

Implementing Jquery Timeago Using PHP.

1 min read 162 words
1 min read
ShareWhatsAppPost on X
  • 1The timeago functionality enhances social networking sites by automatically updating timestamps for better user experience.
  • 2LiveQuery allows jQuery to bind events to dynamically loaded elements, ensuring timeago updates work seamlessly after DOM changes.
  • 3The article provides a simple implementation guide for integrating the timeago plugin with PHP and jQuery for live data updates.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The timeago functionality enhances social networking sites by automatically updating timestamps for better user experience."

— Implementing Jquery Timeago Using PHP.

Nowadays timeago is the most important functionality in social networking sites, it helps to update timestamps automatically. Recent days I received few requests from askgif readers that asked me how to implement timeago plugin with dynamic loading live data using PHP. In this post, I am just presenting a simple tip to implement timeago in a better way.

Why Live Query

LiveQuery utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated.

Code

Contains javascipt code. $(this).timeago()- here this element is referred to timeago class selector of the anchor tag.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.livequery.js"></script>
<script type="text/javascript" src="js/jquery.timeago.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".timeago").livequery(function() // LiveQuery 
{
$(this).timeago(); // Calling Timeago Funtion 
});
});
</script>

//HTML & PHP Code
<?php
$time=time(); // Current timestamp eg: 1371612613
$mtime=date("c", $time); // Converts to date formate 2013-06-19T03:30:13+00:00 
?>

You opened this page <a href='#' class='timeago' title="<?php echo $mtime; ?>"></a>

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 30 August 2019 · 1 min read · 162 words

Part of AskGif Blog · coding

You might also like

Implementing Jquery Timeago Using PHP. | AskGif Blog