I need to display specific group extrafield
- mmmaug1977
-
- Offline
- Moderator
-
Less
More
9 years 3 months ago #2119
by mmmaug1977
Replied by mmmaug1977 on topic I need to display specific group extrafield
Hello Kewwel,
Have you tried this code
If it works with you, then it can be customized to display each group separately.
Have you tried this code
Mohamed Abdelaziz wrote: Hello Jose,
The below code was developed to display extrafields by group, you can use it with a little customization to display extrafields of a specific group with its group id:Code:<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <?php $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select("*")->from("#__k2_extra_fields_groups"); $db->setQuery($query); $groups = $db->loadObjectList('id'); $extraFieldsByGroup = JArrayHelper::pivot($this->item->extra_fields, 'group'); foreach ($extraFieldsByGroup as $groupId => $groupFields){ ?> <h3><?php echo $groups[$groupId]->name; ?></h3> <ul> <?php foreach ($groupFields 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 if($extraField->type == 'header'): ?> <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4> <?php else: ?> <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 class="clr"></div> <?php } ?> </div> <?php endif; ?>
If it works with you, then it can be customized to display each group separately.
Please Log in or Create an account to join the conversation.
- kewwel
- Offline
- New Member
-
Less
More
- Posts: 5
- Thank you received: 0
9 years 3 months ago #2120
by kewwel
Replied by kewwel on topic I need to display specific group extrafield
I tried this code, but shows all. I understand very little of php, so I do not know how to configure each specific group.
Please Log in or Create an account to join the conversation.
- mmmaug1977
-
- Offline
- Moderator
-
9 years 3 months ago #2121
by mmmaug1977
Replied by mmmaug1977 on topic I need to display specific group extrafield
This variant can work with you.
Add this part before any group display code
Then to display a group with its id, use this part:
Add this part before any group display code
Code:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select("*")->from("#__k2_extra_fields_groups");
$db->setQuery($query);
$groups = $db->loadObjectList('id');
$extraFieldsByGroup = JArrayHelper::pivot($this->item->extra_fields, 'group');
?>
<?php endif; ?>
Then to display a group with its id, use this part:
Code:
<?php if (count($extraFieldsByGroup)): ?>
<?php
$groupId = 1; //Replace this with the real group id you want to display
$groupFields = $extraFieldsByGroup[$groupId];
?>
<ul>
<?php foreach ($groupFields 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 if($extraField->type == 'header'): ?>
<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
<?php else: ?>
<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 class="clr"></div>
<?php endif; ?>
</div>
Please Log in or Create an account to join the conversation.