Support » Plugins » Display file date on wordpress page.

  • Resolved rixtertrader

    (@rixtertrader)


    I have a WP page where I display some .gif images.

    At the top of my page I show the DATE that these images were last updated.

    When I update my images, I simply copy the new images over the old ones without changing the file names. This way the new images automatically display (sometimes after a page refresh) and I don’t have to change the filenames within the page links.

    However, I have to manually edit the text “Updated to July 29, 2014” at the top to indicate the images have been updated.

    I figured that perhaps adding some PHP code into the page to read the MODIFY DATE of one of the image files (they are all updated at the same time, so any one of them can be used) and displaying it would do the trick, but it appears you cannot just plop PHP into the page text editor box.

    Any suggestions?

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter rixtertrader

    (@rixtertrader)

    Well, I guess I have to answer my own question as there were no replies or suggestions. Hmmm.

    I figured out a way to do this and am posting it here just in case someone else with limited WP and PHP experience may find a need for it.

    1. I came across a plug-in called Exec PHP that allows me to place PHP code directly into my pages via the WP text editor.

    2. By looking at the page path that is shown at the top when in page editing mode (via the Dashboard), I was able to figure out where my files were located in relation to the page path so I reference my files correctly.

    3. Using PHP within my page, I assigned the full relative path to a variable ($filename = ‘/wp-content/etc/etc/’) and then passed that variable for display via the ECHO command using the Date() and filemtime() funtions.

    Example:

    <?php
    $filename = ‘./wp-content/uploads/2013/Cycles/MyFile.gif’;

    date_default_timezone_set(‘America/Chicago’);

    if (file_exists($filename)) {
    $timecode = filemtime($filename);

    echo “Last updated on:   ” . date(“F d Y”, $timecode);
    }
    ?>

    Now every time I over-write my file MyFile.gif (modify it), the page will show the new ‘updated’ date on the page so my readers would know that it has been updated.

    🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Display file date on wordpress page.’ is closed to new replies.