Skip to content

Instantly share code, notes, and snippets.

@fieke
Created September 18, 2013 08:27
Show Gist options
  • Save fieke/6606235 to your computer and use it in GitHub Desktop.
Save fieke/6606235 to your computer and use it in GitHub Desktop.
Add link to news data
/*
* Implements hook_preprocess_node
*/
function theme_preprocess_node(&$variables, $hook) {
switch ($variables['type']) {
case 'news':
// ADD LINK TO NEWS DATA - HOMEPAGE
if($variables['teaser'] == true && isset($variables['content']['title']['#items']['0']['value'])) {
// GET NODE TITLE, DATE AND NODE URL
$orgdate = $variables['content']['post_date']['#items']['0']['value'];
$orgtitle = strip_tags($variables['content']['title']['#items']['0']['value']);
$linktonode = $variables['node_url'];
// NEW TITLE + DATE VARIABLE
$newtitle = '<div class="teasertitle">' . $orgtitle . '</div> <div class="teaserdate">'. $orgdate.'</div>';
// ADD NODE URL TO DATE
$variables['content']['title']['0']['#markup'] = '<a href="'. $linktonode .'" class="title-date">'. $newtitle .'</a>';
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment