• Hi,

    I’ve been working on a function in the sidebar, but I seem to be stuck. The idea is as follows – I have a set of pages which I update, more or less frequently. I’d like to have a little “new” image or legend, next to the pages I updated less than eg. 10 days ago.

    Example
    ————–
    Pages:
    About
    Photos (new)
    Files

    I’ve managed to mock up some code that checks a date, compare it to a date (10 days ago) and display a gif image or not, depending on the result. I’ve placed this in /wp-include/classes.php around line 520 and it goes like this:
    `$today = current_time(‘timestamp’, 1);
    $offset = $today – 864000; // 10 days offset
    *MISSING VARIABLE, $last_modified*
    $nice_time = substr($last_modified, 0, 10); //just display the date
    $aDate = explode(“-“,$nice_time); //split the date in vars
    $unixtime = mktime(0, 0, 0, $aDate[1], $aDate[2], $aDate[0]); //create epoch timestamp of the date

    if ( $unixtime > $offset ) { //
    $do = “<img src=\”new.gif\”>”;
    `
    It works – apart from the missing variable. I need to fetch the value of “last_modified”. I could do that with a straight forward mysql get, but that seems as bad practice, as the database connections are going on elsewhere.

    Does anyone know of a good approach to this? Or maybe there’s already a plugin that does this? The closest variable I could get a hold on was $last_post_modified, but that’s returns the date of the latest modified post of all posts.. sigh!

    Thanks in advance for input and/or thoughts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Don’t put your code into the core and such. Just put it in your theme, wherever you need it.

    get_the_modified_time() is the function you want, and it would go somewhere in your Loop that’s getting the list of pages.

    Thread Starter netromd

    (@netromd)

    Okay, thanks for the advice. Point taken about the core. So i’ve been looking into sidebar.php, as the page links are generated there. But the way wp_list_pages() works, it’s not easy to add code to each page link.

    I’ve found some code and fitted it to my need:

    $u_time = get_the_time('U');
    $u_modified_time = get_the_modified_time('U');
    if ($u_modified_time <= $u_time - 864000) {
    $display_legend = "<img src=\"new.gif\">";
    }

    Simple indeed – but I can’t figure out where to put it?

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using post_modified to check for recent updates’ is closed to new replies.