Keyword

Show selected extra fields in category listing

  • Suba
  • Suba's Avatar Topic Author
  • Visitor
12 years 3 months ago #67141 by Suba
I have created five extra fields which I want to display in Item view. But in item view in category listings I only want to display two of them. Is this possible with K2? Or is it all or nothing?

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

More
12 years 3 months ago #67142 by william white
Replied by william white on topic Re: Show selected extra fields in category listing
It is possible by overriding the category.php and placing an if statement in the php foreach loop that displays the extra fields and test for the name you do or do not want and let the display accordingly.

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

  • Suba
  • Suba's Avatar Topic Author
  • Visitor
12 years 3 months ago #67143 by Suba
You need to help me a little further. I found the code in category.php, but I cant figure out where and what to test for.
<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.

More
12 years 3 months ago #67144 by william white
Replied by william white on topic Re: Show selected extra fields in category listing
sorry, category_item.php
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
  • Suba's Avatar Topic Author
  • Visitor
12 years 3 months ago #67145 by Suba
Thank you William!

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

  • Voiceconnect Internet Solutions
  • Voiceconnect Internet Solutions's Avatar
  • Offline
  • Junior Member
More
11 years 11 months ago #67146 by Voiceconnect Internet Solutions
Replied by Voiceconnect Internet Solutions on topic Re: Show selected extra fields in category listing
sorry - i am newbie and no coder - could you help just a little more - lets say i have a extra field "Price" and "Model" - with lots more other fields but i only want to display these 2 - what should i put where in this part of code?

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

More
11 years 11 months ago - 11 years 11 months ago #67147 by Lefteris
Hi. We are adding an extra field alias in the next release. This way you can retrieve an extra field using the following code:
<?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

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
11 years 11 months ago #67148 by william white
Replied by william white on topic Re: Show selected extra fields in category listing
@Lefteris This is a really good feature, and simple 2!

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

More
11 years 10 months ago #67149 by Johnnie Kazija
Replied by Johnnie Kazija on topic Re: Show selected extra fields in category listing
could somebody just tell us where exactly we need to place that code? category.php or item?

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

  • Voiceconnect Internet Solutions
  • Voiceconnect Internet Solutions's Avatar
  • Offline
  • Junior Member
More
11 years 10 months ago #67150 by Voiceconnect Internet Solutions
Replied by Voiceconnect Internet Solutions on topic Re: Show selected extra fields in category listing
my result is probably not the best coding, but it works for me in category_item.php look for

<?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.


Powered by Kunena Forum