Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #604237

    Hi there,

    Am using csv files to display data using the plugin wpdatables. My csv files get updated/replaced daily. Is it possible to show on the page a timestamp on when it was last updated? Eg : Last Updated: 29 March 2016, 12:10 am

    I have some php code, unsure where to place it.

    <?php
    // outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.

    $filename = ‘somefile.txt’;
    if (file_exists($filename)) {
    echo “$filename was last modified: ” . date (“F d Y H:i:s.”, filemtime($filename));
    }
    ?>

    Appreciate if you could point me in the right direction, thank you!

    #604285

    Hi janicenisha!

    I loaded the page and can not see any data.
    Where do you want to place the code, can you show us a screenshot and provide us also with backend access?

    Best regards,
    Basilis

    #604478

    Hi Basilis,

    Thank you for replying. The data in the table displayed on the page is from the csv file that gets updated daily.

    Am trying to show a timestamp underneath the table (as per printscreen) to show when the csv was last updated, the thing is am unsure where exactly to place the php code. Below is my access.

    Thank you very much

    #604993

    Hi!

    I’m sorry but it’s not possible to add php codes inside the advance layout builder. Create a shortcode instead. Add this in the functions.php file:

    // [csvmod filename="filenamehere"]
    function csvmodfunc( $atts ) {
        $a = shortcode_atts( array(
            'filename' => 'something.csv'
        ), $atts );
    
    	$directory = $_SERVER["DOCUMENT_ROOT"];
    	$a['filename'] = $directory . $a['filename'];
    
    	if ( file_exists( $a['filename'] ) ) {
    		$output = $a['filename'] . ' was last modified: ' . date ( "F d Y H:i:s.", filemtime( $a['filename'] ) );
    	}
    
        return $output;
    }
    add_shortcode( 'csvmod', 'csvmodfunc' );
    

    In the builder’s text or code block, add something like:

    [csvmod filename="/kriesi/enfold/wp-content/uploads/2015/10/filename.csv"]
    

    Make sure that the directory is correct.

    Cheers!
    Ismael

    #605099

    Hi Ismael,

    Thank you so much for replying. Tried putting the snippet in my functions.php and shortcode in the builder, but nothing shows on the page… any ideas?

    #605613

    Hi!

    Where is the csv file located? I mean the actual folder or directory when you check it on FTP.

    Regards,
    Ismael

    #605646
    #605734

    Hey!

    Is it OK if you move the csv file inside the child theme folder then set the shortcode like this:

    [csvmod filename="/downloads/daily-fund-price/Fund_Price_Website_sample_demo.csv"]
    

    Follow the folder path.

    NOTE: You have to create the downloads > daily-fund-price directory inside the child theme folder.

    Cheers!
    Ismael

    #605837

    Hi Ismael,

    Yup this totally worked. Does this mean I should only use the child theme folder? Shouldn’t be a problem I think but just want t confirm.

    Am so so thankful btw :) Shows exactly how I need it to. Attaching the url below.

    Just one last thing, there is an error on the top of the page : string(62) “/home/hwangimc/public_html/aham/wp-content/themes/enfold-child”

    Cant figure out why

    #606474

    Hi!

    Yup this totally worked. Does this mean I should only use the child theme folder? Shouldn’t be a problem I think but just want t confirm.

    I don’t know the exact setup of the server’s directory so it’s easier to locate the child theme folder.

    Just one last thing, there is an error on the top of the page : string(62) “/home/hwangimc/public_html/aham/wp-content/themes/enfold-child”

    Please edit the code in the functions.php file then look for the var_dump line. Remove it.

    Best regards,
    Ismael

    #606489

    Thanks Ismael, worked great!

    Thank you so much.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Timestamp’ is closed to new replies.