Jump to content

Recommended Posts

Posted

How to display relative dates like the ones we often see in Tumblogs and other social networks?

Examples:

Just now

2 seconds ago
5 minutes ago
2 hours ago

Today

Yesterday
2 days ago
2 weeks ago

I have a feeling it would be kind of tricky, but with PW, who knows :D

Posted

@WillyC - Should I include it somewhere in my frontend template? 

<span class='date'>{$entry->date}</span>

Thanks guys.

Posted

@adrian - Thanks for the link! 
 
So should I create a functions.php file containing the function wireRelativeTimeStr?
 
And in my template I just do what I normally do?
 
<span class='date'>{$entry->date}</span>

Is that correct?

Posted

No, it means this is already supported on global scope in PW:

wireRelativeTimeStr($timestamp);

So try this in your template file to get started:

echo "This page was created " . wireRelativeTimeStr($page->created);


 

Posted

Hey @apeisa,

I'd like to display relative dates in blog posts. Is the code below the best way to do something like this?

<h1>{$blogPost->title}</h1>
<p class='date'>Posted <?php echo wireRelativeTimeStr($blogPost->date); ?></p>
<p>{$blogPost->content}</p>
Posted

If you have datefield called date, then yes, looks good to me. Why not try and see how it works? (never used wireRelativeTimeStr myself)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...