[SOLVED] Extra field only visible when there are 2 in group

More
11 years 7 months ago #1622 by mmmaug1977
Hi Laura,

I have simulated the case on my own development website, and found the problem with the code above, where a group having only one field is returned as an object, not an array as usual, so I have modified the code slightly to fix this issue, please check it:
Code:
<!-------------------- Item extra fields -------------------------> <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <div class="itemExtraFields"> <?php $extraFieldsByGroup = JArrayHelper::pivot($this->item->extra_fields, 'group'); $db = JFactory::getDbo(); $query = "SELECT * FROM #__k2_extra_fields_groups"; $db->setQuery($query); $groups = $db->loadAssocList('id'); foreach ($extraFieldsByGroup as $key=>$extrafields){ $defaultGroup = ''; if(!is_array($extrafields)) $extrafields = array($extrafields); if($key == $this->item->category->extraFieldsGroup) $defaultGroup = "class='mefg_default'"; ?> <div id="group" class="<?php echo $groups[$key]['name'];?>" > <table class="<?php echo $groups[$key]['name'];?>"> <tr><td colspan="2"><h3><?php echo JText::_($groups[$key]['name']); ?></h3></td></tr> <!--<ul>--> <?php foreach ($extrafields as $key=>$extraField): ?> <?php if($extraField->value != ''): ?> <?php /*?><li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"><?php */?> <?php if($extraField->type == 'header'): ?> <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4> <?php else: ?> <tr> <td class="name" valign="top"><span class="itemExtraFieldsLabel"><?php echo JText::_($extraField->name); ?>:</span></td> <td class="value"><span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span></td></tr> <?php endif; ?> <!--</li>--> <?php endif; ?> <?php endforeach; ?> <!--</ul>--> </table></div> <?php } ?> <div class="clr"></div> </div> <?php endif; ?>

Please Log in or Create an account to join the conversation.

  • lcp298
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 7 months ago #1623 by lcp298
That seems to have done it, thanks :-)

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum