2

I want to check if the node is not a static page, and display $date in "node.tpl.php" within this <div>:

<div id="postDateArea"></div>

I currently have this in my node.tpl.php file:

<div id="postDateArea"><?php print $date; ?></div>

I currently have this in my template.php file:

function thebridge_preprocess_node(&$vars) {
  if($vars['type'] != 'static_page') {
  }
}

2 Answers 2

3
function thebridge_preprocess_node(&$vars) {
  if($vars['type'] != 'static_page') {
    $vars['date'] = date('Y-m-d');
  }
}

You might want to change the parameters of date(). More information in the Drupal documentation.

3

You can use the format_date function:

function thebridge_preprocess_node(&$vars) {
  $vars['date'] = format_date($vars['node']->created);
}

There are more parameters to format_date, most important the 'custom' format which allows for a custom PHP date() format.

function thebridge_preprocess_node(&$vars) {
  $vars['date'] = format_date($vars['node']->created, 'custom', 'F j');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.