Skip to content

Instantly share code, notes, and snippets.

@kricore
Last active January 3, 2016 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kricore/3ab3d73856417edf3689 to your computer and use it in GitHub Desktop.
Save kricore/3ab3d73856417edf3689 to your computer and use it in GitHub Desktop.
Just a normal K2 extrafields loop with the addition of icon fonts for social links instead of simple links.. It requires the use of the extrafields aliases (eg twitter, facebook etc). The icon- and -circled prefix and suffixed are based on the Entypo icon font from Fontello.
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<?php /*<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>*/ ?>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<?php // Check if it is a social link
$ealias = $extraField->alias;
?>
<?php if(preg_match('[facebook|twitter|linkedin|gplus|vimeo|skype|youtube|dribbble|flickr|pinterest|tumblr]', $ealias)): ?>
<?php if($extraField->type == 'header'): ?>
<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
<?php else: ?>
<?php
// clean up the content
$string = $extraField->value;
$initial = '">';
$replacement = '"><i class="icon-'.$extraField->alias.'-circled"></i><span class="hidden">';
$first = str_replace($initial, $replacement, $string);
// once again add markup at the end
$secondString = $first;
$secondInit = '</a>';
$secondRep = '</span></a>';
// final result
$final = str_replace($secondInit, $secondRep, $secondString);
?>
<span class="itemExtraFieldsValue">
<?php echo $final; ?>
</span>
<?php endif; ?>
<?php else: // Not a social link - display default extrafields ?>
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment