Monday, 19 October 2015 12:15

Text limit in Joomla

For com_content use the following:

<?php $truncated_text = JHtml::_('string.truncate', $this->item->introtext, 20); ?>
<?php echo $this->item->event->beforeDisplayContent; ?> <?php echo $truncated_text; ?>

For K2 use the following:

<?php echo JHtml::_('string.truncate', $this->item->introtext, 200); ?>
Published in Blog
Sunday, 23 August 2015 04:16

Output specific K2 extra fields

Outputing specific K2 extra fields is dependent on what php document you intend to display the extra fields in. If you're using item.php, or the category-item.php files, the following should work. In the top of the document, add this code:

<!-- Call to prepare extra fields -->
$extrafields = array();
foreach($this->item->extra_fields as $item)
$extrafields[$item->id] = $item->value;
Then, wherever you'd like to call the value of the filled in field, use this:

<?php if($extrafields[ID_NUMBER_OF_FIELD]!=''):?> <!-- if filled in, then call data -->
<?php echo $extrafields[ID_NUMBER_OF_FIELD];?> <!-- actual data call -->
<?php endif; ?>
tag.php works a little differently, as do the K2 Modules.

for tag.php you don't need the extra code in the head, the following will call your field data:

<?php $extrafields = json_decode($item->extra_fields);?>
<?php foreach($extrafields as $key=>$value): ?>
<?php if($extrafields[$key]->id == 'ID_NUMBER_OF_FIELD'&&$extrafields[$key]->value!=''): ?>
<?php echo $extrafields[$key]->value; ?>,
<?php endif; ?>
<?php endforeach; ?>
Again, with the module_k2_content, you don't need the top data call. Get your field data this way:

<?php echo $item->extraFields->ALIAS_OF_FIELD->value ;?>


For menu links that use the K2 Latest Items layout, call the extra fields within the template override using the following:

<?php $extrafields = json_decode($this->item->extra_fields);?>
<?php foreach($extrafields as $key=>$value): ?>
<?php if($extrafields[$key]->id == '1'&&$extrafields[$key]->value!=''): ?>
<?php echo $extrafields[$key]->value; ?>
<?php endif; ?>
<?php endforeach; ?>

Published in Blog

I knocked up this video explaining how the "read more" divider in k2 works, and how it can effect content that contains elements such as lists within the intro text.

Published in Blog