WordPress.org

Ready to get started?Download WordPress

Forums

How to display a timestamp lik: 18 days ago on front page only, normal elsewhere (5 posts)

  1. Aurox
    Member
    Posted 2 years ago #

    How to display on the first page when the article was submit, for example: 18 days ago, 2 minutes ago and to display the date on the other pages.
    I understand it should use a if else condition.
    Thanks.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

  3. Aurox
    Member
    Posted 2 years ago #

    thanks for your answer.

    This code didn't worked.

    <?php
    if ( is_front_page() ) {
        echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
    } else {
       echo 'x';
    }
    ?>

    Is just displaying like "2 hours ago" even if I'm on page 2.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    even if I'm on page 2

    that is what is_paged() is for.

    example:
    if ( is_front_page() && !is_paged() )

    or try:

    if ( is_home() && !is_paged() )

  5. Aurox
    Member
    Posted 2 years ago #

    Worked with this, thank you sir.

    <?php
    if ( is_home() && !is_paged() ) {
        echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
    } else {
       echo the_time('d.m.Y');
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags