0

I want to show the blog posts'time like below:

"A heading title , posted by XYZ, 1 hour ago"

I want the time that says: 5 minutes ago, 1 hour ago, 2 days ago 1 month ago like that.

how can i get this working?

i can't get the exact wordpress API code to implement it. Please help.

2

In your template where you see the_title(), you will want to change it to something along the following:

echo get_the_title() . ', ' .
    'posted by ' . 
    get_the_author() . ', ' .
    human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . 
    ' ago';

human_time_diff() is the one doing the part regarding your topic. Though you also asked for the others.

However, if you want it to look even cleaner, try:

printf(
    '<h2>%s, posted by %s, %s ago</h2>',
    get_the_title(),
    get_the_author(),
    human_time_diff( 
        get_the_time( 'U' ), 
        current_time( 'timestamp' )
    )
);

Replacing whatever tag/formatting you want in the first parameter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.