Keyword

Limiting Extra FieldsDisplay

  • CuppaJoe
  • CuppaJoe's Avatar Topic Author
  • Offline
  • New Member
  • Share The Warmth
More
10 years 9 months ago #125224 by CuppaJoe
Limiting Extra FieldsDisplay was created by CuppaJoe
Hello Everyone.

I have 15 extra field codes to add to each item in a category.

Is there a way, using some custom code added to my K2 template, that will allow limiting the number of extra fields that are shown in the category_item.

If I set my category to show extra fields, then all 15 will be displayed, but what if I want to display just the first five, or even specific extra field can this be done by their alias.

Any help is appreciated.

Joe

Regards,

Joe,

ShareTheWarmth

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

More
10 years 9 months ago - 10 years 9 months ago #125225 by Hardkiffeur
Replied by Hardkiffeur on topic Re: Limiting Extra FieldsDisplay
Hi Cuppa,

You could rewrite how the extrafields's list is publish in the itemExtraFields bloc (on the category_item.php) , just after
<div class="itemExtraFields">
<ul>

Exemple : First extrafield's alias is EXTRA1 and a second EXTRA2 (alias could be read on the K2 item's list)

<li class="odd"><span class="itemExtraFieldsLabel"><?php echo $this->item->extraFields->EXTRA1->name; ?></span><span class="itemExtraFieldsValue"><?php echo $this->item->extraFields->EXTRA1->value; ?></span></li>
<li class="even"><span class="itemExtraFieldsLabel"><?php echo $this->item->extraFields->EXTRA2->name; ?></span><span class="itemExtraFieldsValue"><?php echo $this->item->extraFields->EXTRA2->value; ?></span></li>

and so on with the Extrafields, Alias you want to show ;)

I assume you already do an override template and assigne it t the categorie you want to work with ;)

Let me know

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

  • CuppaJoe
  • CuppaJoe's Avatar Topic Author
  • Offline
  • New Member
  • Share The Warmth
More
10 years 9 months ago #125226 by CuppaJoe
Replied by CuppaJoe on topic Re: Limiting Extra FieldsDisplay
Thank you friend,

That looks like it would work lovely.
Yes, always use over rides.

Joe

Regards,

Joe,

ShareTheWarmth

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

More
10 years 8 months ago #125227 by Nikos
Replied by Nikos on topic Re: Limiting Extra FieldsDisplay

hardkiffeur wrote: Hi Cuppa,

You could rewrite how the extrafields's list is publish in the itemExtraFields bloc (on the category_item.php) , just after
<div class="itemExtraFields">
<ul>

Exemple : First extrafield's alias is EXTRA1 and a second EXTRA2 (alias could be read on the K2 item's list)

<li class="odd"><span class="itemExtraFieldsLabel"><?php echo $this->item->extraFields->EXTRA1->name; ?></span><span class="itemExtraFieldsValue"><?php echo $this->item->extraFields->EXTRA1->value; ?></span></li>
<li class="even"><span class="itemExtraFieldsLabel"><?php echo $this->item->extraFields->EXTRA2->name; ?></span><span class="itemExtraFieldsValue"><?php echo $this->item->extraFields->EXTRA2->value; ?></span></li>

and so on with the Extrafields, Alias you want to show ;)

I assume you already do an override template and assigne it t the categorie you want to work with ;)

Let me know

Hello and hope to get this work,
So I would be pleased if you could tell me where exactly should I make the copy of category_item.php in order to get this override to work. What if I needed those specific extra fields to be shown in every item in the category view? I inserted the code that you suggested and nothing happened. I checked which template I'm using for the category that I want to implement this and it's the default. So I have to change the file which is into /components/com_k2/templates/default/category_item.php . Could you please explain it in more details? Sorry for asking something like that but I am new to K2 but I have a bit of knowledge in php.
Thank you in advanced.

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

More
10 years 8 months ago #125228 by Lefteris
Replied by Lefteris on topic Re: Limiting Extra FieldsDisplay
@Nikos

Please take first a read regarding K2 templating at getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

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

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

More
10 years 8 months ago - 10 years 8 months ago #125229 by Nikos
Replied by Nikos on topic Re: Limiting Extra FieldsDisplay

Lefteris Kavadas wrote: @Nikos

Please take first a read regarding K2 templating at getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Hello Lefteri,
I have read this documentation already and it didn't work for me that way. I had to create another folder named template into templates/mytemplate/html/com_k2/TEMPLATE/default or blog in order to select it as a template of my category in k2 back-end. So I did that and still if I make any changes into category_item.php for instance it does not affect anything. I tried to delete this file and still nothing happened.
Let's try something else. If I wanted to make some changes in the category view, the file that I should change is the category_item.php which is in the path components/com_k2/template/default provided that I have selected default template in k2 back-end for the category template. Right?

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

More
10 years 8 months ago - 10 years 8 months ago #125230 by Nikos
Replied by Nikos on topic Re: Limiting Extra FieldsDisplay
I just wanted to share this with you in this video between 6-8 minutes explains how to use the extra fields or specific extra fields. Even it is in Spanish (the speaker) everything else is in English ;)



Thank you for your help though.

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

More
10 years 8 months ago #125231 by Lefteris
Replied by Lefteris on topic Re: Limiting Extra FieldsDisplay
If you want to change the category page of the default template then you need to change the files
/templates/YOURTEMPLATE/html/com_k2/default/category.php
/templates/YOURTEMPLATE/html/com_k2/default/category_item.php
depending on the part you wish to change. Note that when you are making a menu link to multiple categories then the template needs to be set in the menu link settings.

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

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

  • CuppaJoe
  • CuppaJoe's Avatar Topic Author
  • Offline
  • New Member
  • Share The Warmth
More
10 years 8 months ago #125232 by CuppaJoe
Replied by CuppaJoe on topic Re: Limiting Extra FieldsDisplay
Hey All,

I used a slightly simpler/dirty way some might say.
My example below was added to the item.php as follows:
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
      <?php if($extraField->value): ?>
		<li class="type<?php echo ucfirst($extraField->alias); ?> group<?php echo $extraField->group; ?>">
			<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
			<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
                 </li>
      <?php endif; ?>
<?php endforeach; ?>

The key is adding the extra fields alias to the list class, this way a custom class can be coded for that extra field and hidden or restyled as required.

Thanks to Simon at K2Joom for the suggestion.

Regards,

Joe,

ShareTheWarmth

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
10 years 8 months ago #125233 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: Limiting Extra FieldsDisplay
@CuppaJoe

I thought in a modification to your way, that can be used in this case, without having the fields html in the document but hiding them with CSS.

You can create an array with the field ids either to show or to hide, which is shorter.
Lets assume that the shorter list is the fields to show, then the code will be like this:
<?php $fieldsToShow = array(1,5,7,13); //this is an array of fields keys/ids to show ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
      <?php if(in_array($key, $fieldsToShow)): ?>
             <li class="type<?php echo ucfirst($extraField->alias); ?> group<?php echo $extraField->group; ?>">
                     <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                       <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
                 </li>
      <?php endif; ?>
<?php endforeach; ?>

This way, only the html code of the fields to show will be there.
Also it easy to modify the $fieldsToShow array if you changed your mind.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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


Powered by Kunena Forum