Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 96
  • Last Modified:

Using php in body to display modified date of particular web page for Drupal 7.33

I am a user of a Drupal 7 system that was given the permissions to create and publish new web pages for the site.

I would like to know if there is an easy way to display the last modified date on the web page using php.

I found this snippet, but it only displays the current date:  

<?php
   echo date('m/d/Y');
?>

I need to display the last modified date only on some selected pages--not all pages on the web site, so I do not want to change the template (I don't have access to the templates or any of the theme files or other system files.

Thanks!
0
scottlum
Asked:
scottlum
1 Solution
 
Aaron FeledyDrupal Developer and ConsultantCommented:
Using the php filter, you can do this:
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $date = date('m/d/Y', $node->changed);
  print $date;
}
?>

Open in new window


It checks the path to be sure it's a node, then loads the information about the node. It then formats the "changed" date and prints it.
0
 
scottlumAuthor Commented:
Excellent--exactly what I'm looking for--thanks!!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now