- Posts: 3722
COMMUNITY FORUM
Show selected extra fields in category listing
- Suba
-
Topic Author
- Visitor
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Please Log in or Create an account to join the conversation.
- Suba
-
Topic Author
- Visitor
<div id="itemListLinks">
<h4><?php echo JText::_('K2_MORE'); ?></h4>
<?php foreach($this->links as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_links_columns'))==0) || count($this->links)<$this->params->get('num_links_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->links)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_links_columns'), 1).'%;"'; ?>>
<?php
// Load category_item_links.php by default
$this->item=$item;
echo $this->loadTemplate('item_links');
?>
</div>
<?php if(($key+1)%($this->params->get('num_links_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
search for this <!-- Item extra fields --> and you will find the xtra field display just below it
around line 129 looks like this
[code]
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="catItemExtraFields">
<h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4>
<ul>
<?php foreach ($this->item->extra_fields 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; ?>">
<span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
<span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
{/code]
you can test the extra field label for know values and skip the field else just display it as a part of the loop
Please Log in or Create an account to join the conversation.
- Suba
-
Topic Author
- Visitor
Please Log in or Create an account to join the conversation.
- Voiceconnect Internet Solutions
-
- Offline
- Junior Member
- Posts: 39
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
<?php echo $this->item->extraFields->ALIAS->name; ?>
<?php echo $this->item->extraFields->ALIAS->value; ?>
Note that depending on the context you may need to change the code to :
<?php echo $item->extraFields->ALIAS->name; ?>
<?php echo $item->extraFields->ALIAS->value; ?>
The ALIAS is referring to the extra field alias which can be set in the extra field edit form.
The above code will work in the next release for K2. It does not work on K2 2.6.1. If you need this you can grab a copy of the SVN version at getk2.org/assets/svn
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- Johnnie Kazija
-
- Offline
- Senior Member
Please Log in or Create an account to join the conversation.
- Voiceconnect Internet Solutions
-
- Offline
- Junior Member
- Posts: 39
<?php if($extraField->value): ?>
<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 endif; ?>
now you basically replace the first line with: <?php if ($extraField->id == '6'): ?>
replace the 6 with the id of the extra field you want to display - now i have 2 fields i display so i have the code twice below each other inside the <?php foreach code part like below
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if ($extraField->id == '6'): ?>
<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 endif; ?>
<?php if ($extraField->id == '9'): ?>
<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">R<?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
like i said - it might not make sense for the coding gurus but it works for me
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
see getk2.org/blog/item/1068-k2-v262-now-available
Please Log in or Create an account to join the conversation.
- Voiceconnect Internet Solutions
-
- Offline
- Junior Member
- Posts: 39
i have now tried to use the same code in the tag list but it does not work - below is the code i am using that works in category but not in tags
<div class="farmprice">
<?php echo $this->item->extraFields->PriceinRmil->name; ?> <?php echo ' : '; ?>
<?php echo $this->item->extraFields->PriceinRmil->value; ?>
</div>
could you shed some light on my problem?
Please Log in or Create an account to join the conversation.
- klikeri
-
- Offline
- New Member
- Posts: 12
But, I get value in <p> ..</p> tag. I would like to change that. Where I can do it?
Problem with echo name return ".." in code pls check
Thanks
Please Log in or Create an account to join the conversation.