How to display extra fields in article with K2

Tibi picture Tibi · Oct 5, 2010 · Viewed 16.9k times · Source

currently I've got Jreviews installed and I'd like to replace it by K2 to list specialized shops with addresses, phones, maps, opening hours ...

With K2 I guess I'll need to define extra custom fields to hold those specific information. No problem.

But, how may I configure things to have those fields displayed in the detailed article/items for a specific shop ?

Many thanks,

Tibi.

Answer

Hari Honor picture Hari Honor · Dec 16, 2010
// In the item template you can skip this first line...
$this->item->extra_fields = K2ModelItem::getItemExtraFields($this->item->extra_fields);

$extraFlds = array();
if ( $this->item->extra_fields ){
  foreach ( $this->item->extra_fields as $key=>$extraField ){
     $extraFlds[ $extraField->name ] = $extraField->value;
  }
}

Then you can access your extra fields in the associate array like $extraFlds['my field']