Skip to content

Instantly share code, notes, and snippets.

@mglaman
Created June 4, 2014 01:25
Show Gist options
  • Save mglaman/5d0a10de68b3e23a391c to your computer and use it in GitHub Desktop.
Save mglaman/5d0a10de68b3e23a391c to your computer and use it in GitHub Desktop.
Fancy article tag formatting. Expects "field_tags" to exist and a term reference field.
<?php
// Voila! $submitted now has date and tags.
?>
<p class="submitted"><?php print $submitted; ?></p>
<?php
function glamanate_preprocess_node(&$variables) {
$node = $variables['node'];
$date = format_date($variables['created'], 'published');
$variables['submitted'] = t('@date', array('@date' => $date, '!author' => $variables['name']));
//Find out the tags
if (isset($node->field_tags) && $variables['page']) {
$article_field_tags = field_get_items('node', $node, 'field_tags');
$article_tags = array();
if(!empty($article_field_tags)) {
foreach($article_field_tags as $tag) {
$tag_link = t('<a href="@url" title="View articles about @tag">@tag</a>',
array('@url' => url('taxonomy/term/'.$tag['tid'], array('absolute' => true)), '@tag' => $tag['taxonomy_term']->name));
$article_tags[] = $tag_link;
}
$article_tags_inline =implode(', ', $article_tags);
$variables['submitted'] .= " | tags: " . $article_tags_inline;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment