- Posts: 1
COMMUNITY FORUM
Echo extra field into category_item.php
- DCA
-
Topic Author
- Offline
- New Member
Less
More
15 years 5 months ago #75622
by DCA
Echo extra field into category_item.php was created by DCA
Guys, is possible to show custom fields at "category_item.php" page?
I look for how I could do this trick but without success, I tested with a basic echo:
echo $this->item->extra_fields[0]->value;
Nothing...
I also copy a part of foreach from "item.php" page but I got a error.
I look for how I could do this trick but without success, I tested with a basic echo:
echo $this->item->extra_fields[0]->value;
Nothing...
I also copy a part of foreach from "item.php" page but I got a error.
Please Log in or Create an account to join the conversation.
- ANDiTKO
-
- Offline
- New Member
Less
More
- Posts: 2
14 years 3 months ago #75623
by ANDiTKO
Replied by ANDiTKO on topic Echo extra field into category_item.php
Add this line in the begining of your category_item.php file:
$this->item->extra_fields = K2ModelItem::getItemExtraFields($this->item->extra_fields);
Then you can echo or call your custom fields like this:
echo $this->item->extra_fields[0]->value;
$this->item->extra_fields = K2ModelItem::getItemExtraFields($this->item->extra_fields);
Then you can echo or call your custom fields like this:
echo $this->item->extra_fields[0]->value;
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
Less
More
- Posts: 663
14 years 3 months ago #75624
by BBC
Replied by BBC on topic Echo extra field into category_item.php
It should be some documentation how to call extra fields.
This way this stupid forum software strips code.
This way this stupid forum software strips code.
Please Log in or Create an account to join the conversation.
- rawling
-
- Offline
- Junior Member
Less
More
- Posts: 23
14 years 3 months ago #75625
by rawling
Replied by rawling on topic Echo extra field into category_item.php
this sample shov only 3 extra-field: "Fone", "Price" and "Color";
replace block kode about line 132:
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('Additional Info'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> </li> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?>
with this kode
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFieldsLast"> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <?php /* sample */; ?> <?php $emptyValue = false; switch ($extraField->type) { case "textfield": case "textarea": if ($extraField->value =="") $emptyValue = true; break; case "link": if (strpos($extraField->value,"\"http://\"")) $emptyValue = true; break; case "radio": break; case "multipleSelect": // Test already done by K2. If value is empty, this type of field does not appear. break; case "select": // This type of field can't have an empty value (first item select by default) break; } ?> <?php if (!$emptyValue): ?> <?php //echo $extraField->name; ?> <?php if (($extraField->name=="Fone") || ($extraField->name=="Price") || ($extraField->name=="Color")): ?> <span class="itemExtraFieldsLastLabel"><?php echo $extraField->name; ?>:</span> <span class="itemExtraFieldsLastValue"><?php echo $extraField->value; ?></span> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> <div class="clr"></div> <?php if ($this->item->params->get('catItemReadMore')): ?> <!-- Item "read more..." link --> <div class="latestItemReadMore"> <a class="k2ReadMore" href="<?php echo $this->item->link; ?>"> <?php echo JText::_('Read more...'); ?> </a> <!--<div class="clr"></div> --> </div> <?php endif; ?> </div> <?php endif; ?>
replace block kode about line 132:
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('Additional Info'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> </li> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?>
with this kode
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFieldsLast"> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <?php /* sample */; ?> <?php $emptyValue = false; switch ($extraField->type) { case "textfield": case "textarea": if ($extraField->value =="") $emptyValue = true; break; case "link": if (strpos($extraField->value,"\"http://\"")) $emptyValue = true; break; case "radio": break; case "multipleSelect": // Test already done by K2. If value is empty, this type of field does not appear. break; case "select": // This type of field can't have an empty value (first item select by default) break; } ?> <?php if (!$emptyValue): ?> <?php //echo $extraField->name; ?> <?php if (($extraField->name=="Fone") || ($extraField->name=="Price") || ($extraField->name=="Color")): ?> <span class="itemExtraFieldsLastLabel"><?php echo $extraField->name; ?>:</span> <span class="itemExtraFieldsLastValue"><?php echo $extraField->value; ?></span> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> <div class="clr"></div> <?php if ($this->item->params->get('catItemReadMore')): ?> <!-- Item "read more..." link --> <div class="latestItemReadMore"> <a class="k2ReadMore" href="<?php echo $this->item->link; ?>"> <?php echo JText::_('Read more...'); ?> </a> <!--<div class="clr"></div> --> </div> <?php endif; ?> </div> <?php endif; ?>
Please Log in or Create an account to join the conversation.
- Dene Goodwin
-
- Offline
- New Member
Less
More
- Posts: 1
13 years 10 months ago #75626
by Dene Goodwin
Replied by Dene Goodwin on topic Echo extra field into category_item.php
Worked perfectly. Thanks Rawling
Please Log in or Create an account to join the conversation.