• openbayou

    (@openbayou)


    My theme has the date published as “___ ago” and it caches whatever the post was created. For example, if the post was cached as “9 seconds ago” then it shows “9 seconds ago” when you visit the page the next day. Is there anyway to have it not cache the date?

    Thanks.

    My theme’s functions.php:

    function db_relative_time() {
    $post_date = get_the_time('U');
    $current_time = current_time('timestamp');
    $time_difference = $current_time - $post_date;
    if ($time_difference < 60) {
        echo strval(round(($time_difference))), ' seconds ago';
    } elseif ($time_difference < 2 * YEAR_IN_SECONDS) {
        echo human_time_diff($post_date, $current_time) . ' ago';
    } else {
        if (get_the_time('Y') !== date('Y')) {
            echo get_the_time('M. d, Y');
        } else {
            echo get_the_time('M. d');
        }
    }
    }

    My theme’s index.php:

        <div class="right-info">
            <div class="contain">
                <div class="top-line"><span class="strong"><?php the_author(); ?></span> posted an <span class="strong">update</span></div>
                <div class="bottom-line">
                    <a href="<?php echo get_permalink();?>"><?php echo db_relative_time();?></a>  // date is displayed
                </div>
            </div>
        </div>
Viewing 1 replies (of 1 total)
  • Plugin Author Emre Vona

    (@emrevona)

    when a page is cached, the page is saved as a static html file so PHP does not work. You should load the data via Ajax.

Viewing 1 replies (of 1 total)
  • The topic ‘How to not cache the date?’ is closed to new replies.