-
AuthorPosts
-
March 29, 2016 at 5:12 am #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!
March 29, 2016 at 7:09 am #604285Hi 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,
BasilisMarch 29, 2016 at 1:08 pm #604478Hi 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
March 30, 2016 at 7:14 am #604993Hi!
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!
IsmaelMarch 30, 2016 at 12:02 pm #605099Hi 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?
March 31, 2016 at 4:46 am #605613Hi!
Where is the csv file located? I mean the actual folder or directory when you check it on FTP.
Regards,
IsmaelMarch 31, 2016 at 6:39 am #605646Hi Ismael,
The csv file sits here : http://103.51.41.206/~hwangimc/downloads/daily-fund-price/Fund_Price_Website_sample_demo.csv
Thanks
March 31, 2016 at 9:43 am #605734Hey!
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!
IsmaelMarch 31, 2016 at 12:54 pm #605837Hi 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
April 1, 2016 at 5:25 am #606474Hi!
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,
IsmaelApril 1, 2016 at 6:12 am #606489Thanks Ismael, worked great!
Thank you so much.
-
AuthorPosts
- The topic ‘Timestamp’ is closed to new replies.