Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get a page's last modification date?
#1
How do I get a page's last modification date analogous to a page's creation date?

I saw that last mod date is used in the backend, but I was unable to find the function. Sight's getting kind of blurry at this time of the night. Maybe someone can help me out?
Reply
#2
You could always use the php filemtime() function:
Code:
$filename = "somepage.xml";
filemtime($filename));
http://php.net/manual/en/function.filemtime.php

Or there is the 'pubDate' node in each xml file which tells the last modified date and time
Reply
#3
polyfragmented Wrote:How do I get a page's last modification date analogous to a page's creation date?

I saw that last mod date is used in the backend, but I was unable to find the function. Sight's getting kind of blurry at this time of the night. Maybe someone can help me out?

On the front end to get the current page's last modification date: get_page_date(...)
With the I18N Customfields plugin to get the creation date: get_page_creation_date(...)

In the xml page files as strings: pubDate and creDate
Convert them to Unix time stamps: strtotime(...)
Format a Unix time stamp locale specific: setLocale(...); strftime(...)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#4
(2011-04-24, 11:02:26)mikeh Wrote: You could always use the php filemtime() function

I'd like to ask about using the filemtime() function in GetSimple CMS.

I test my web on localhost (on Linux) for now and want to know the last modification time of a page that has the slug "important". After some attempts, I have discovered that only the absolute filesystem's path to the file in question works (" filemtime("/var/www/html/tmt/data/pages/important.xml") "). But this naturally will stop working after moving the web to a webserver. I tried to write a relative path to the file (in relation to what starting point? - the script is in the file theme/Innovation/template.php) or an absolute path using "http://localhost/" but I haven't succeed. So what path should I set in a production webserver?
Reply
#5
first of, you should detect the 'full path' of your xml file. You can do it with pwd command on ssh console from directory where the file is located.

Or you can do it with php from your template.php file:

Code:
<?php echo __DIR__; ?>

you get something like this: /var/bla-bla/foo/theme/Innovation

so you can extend it with the relative path to your xml file: /var/bla-bla/foo/data/pages/important.xml
Reply
#6
PS. if it's the GS pages directory, maybe better to do it with the GS constant GSDATAPAGESPATH

Code:
filemtime(GSDATAPAGESPATH.important.xml)
Reply
#7
Thank you very much.

The second one correctly should be
Code:
filemtime(GSDATAPAGESPATH."important.xml")

Information about the GSDATAPAGESPATH constant should maybe be added in the wiki.
Reply




Users browsing this thread: 2 Guest(s)