Im trying to get ExtraFields from K2 Articles. I have assigned my menu to Latest from Users or Categories
in order to display all articles from several categories.
It displays fine. But these articles have ExtraFields information that I want to display, but there is no option to display ExtraFields, so I suppose that in order to do this I need to change latest.php
page, which is the page used to display all articles from different Categories.
As latest.php
doesn't display ExtraFields I'm trying to code it as the following:
<?php
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
<?php if(isset($extrafields[X]) === true):?>
<?php echo $extrafields[X]; ?>
<?php endif; ?>
Though, I'm getting the following error:
Invalid argument supplied for foreach() in ...
I've been searching ways to get ExtraFields, found some solutions but this is the error i get every time.
Any ideas or solutions?
Best regards.
I'm using joomla 2.5.
$item->extra_fields
seems to be something different than an array. If you need a better answer, you should provide more details. Which 'lastest.php'? WhichExtraFields
?$this->item
contains extra fields. Please do avar_dump($this->item);
and check for extra fields there.latest.php
is part ofcom_k2
, and (at least in the J3.5-version) has a subtemplate calledlatest_item.php
. Create a template override of this one and edit. (and for the template override don't miss to copy the whole foldercom_k2/templates
since the overriding only works with the files lying in that folder.)