Keyword

SOLVED: Tutorial for extra fields?

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago - 12 years 3 months ago #103205 by Johann Scharfetter
SOLVED: Tutorial for extra fields? was created by Johann Scharfetter
Hello!

I'm new to K2. I wonder where there is a tutorial or a video about how to create templates with extra fields?

Please could you indicate me wher to find it, if there is any?
I'm an absolute beginner in php.

THANK YOU!

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

More
12 years 8 months ago #103206 by william white
Replied by william white on topic Re: Tutorial for extra fields?
getk2.org/documentation/k2class2012
a good place to start

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago - 12 years 8 months ago #103207 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Tutorial for extra fields?
Hello,

what I found out till now ist the following code:

Log in  or Create an account to join the conversation.

More
12 years 8 months ago #103208 by Lefteris
Replied by Lefteris on topic Re: Tutorial for extra fields?
@scharfet

What exactly are you trying to achieve? The extra fields are being displayed automatically since you have set up accordingly the category settings.

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago - 12 years 8 months ago #103209 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Tutorial for extra fields?

Lefteris Kavadas wrote: @scharfet

What exactly are you trying to achieve? The extra fields are being displayed automatically since you have set up accordingly the category settings.


Hi!

The default method despays the extra fields in a simple table format.
But I want do display the extra fields as I need it.

For instance: I have 6 extrafields that are 3 questions and 3 answers which I would like to display in a slider as you can see here.
iteplus.es/marenostrum/index.php?option=com_k2&view=item&layout=item&id=1&Itemid=134#%C2%BFc%C3%B3mo-vemos-la-homeopat%C3%ADa-en-marenostrum

An other thng: I have an extra field which should be displayed in a div with different css styles (pink background)

I want to get this: estudiohr.com/clientes/marenostrum/03.html

What I want to ask is what is the correct way to add extra fields to a k2-template? (Not using the standard display of extra fields in a table.)

I hope I could explain myself clearly.

Thank you!

======================================================

William White wrote: getk2.org/documentation/k2class2012
a good place to start

Hi William,
I have watched all the vidios on this page, but none of them are informing about extra fields and how to display them in a template.

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

More
12 years 8 months ago #103210 by Lefteris
Replied by Lefteris on topic Re: Tutorial for extra fields?
Make a template override to item.php and then manipulate the output as you wish. Since you have specific styles for specific fields you may need to target your fields by using their id.

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago - 12 years 7 months ago #103211 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Tutorial for extra fields?
Hello!

How to display extra fields?

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 7 months ago - 12 years 7 months ago #103212 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Tutorial for extra fields?
Hello!

I need to know whether this code is the best way to display extra fields.
Log in  or Create an account to join the conversation.

More
12 years 5 months ago #103213 by mahdi
Replied by mahdi on topic Re: Tutorial for extra fields?

William White wrote: getk2.org/documentation/k2class2012
a good place to start

I feel your answers is reluctantly
Because most of them are not efficient

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 4 months ago - 12 years 4 months ago #103214 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Tutorial for extra fields?
New website:

Hello,

I tried to add extra fields to a certain position in K2 item view in a new website.

What I did:
1.) In the Category-settings: the correct extra fields group is associated (Associated "Extra Fields Group")

2.) I added this code to item.php
Log in  or Create an account to join the conversation.

More
12 years 3 months ago #103215 by Napolian Stewart
Replied by Napolian Stewart on topic Re: Tutorial for extra fields?
Scharfet,

Try it without the single quotes around the IDs, like this - [1] - instead of this - .

This works for me, except the tabs don't render for me.
Log in  or Create an account to join the conversation.

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 3 months ago #103216 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: SOLVED: Tutorial for extra fields?
Hi Poe,

it is working now. You were right the code had errors.

For others who wants to know how to use "Extra Fields" in a personalized way in "Item view".
In "Category" > "Item View Options " > "Extra Fields" > it is necesary to choose "Show".
The extra fields will be displayed also in the standard way (in a table). This code need to be deleted forom item.php.

At the beginning of the item.php place following code.
Log in  or Create an account to join the conversation.

More
12 years 2 weeks ago #103217 by Odin Mayland
Replied by Odin Mayland on topic Re: SOLVED: Tutorial for extra fields?
I can get this to work in category.php but only at the end of the code. I want the extrafields to appear after the subcategories and before the items.

The first screen shot shows the code working after the item list:

Attachment not found





The second screenshot shows the same code in the same category.php file but the extrafields are not showing:

Attachment not found




I can't figure out why the same code will not work in a different location.
Attachments:

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

More
10 years 8 months ago - 10 years 8 months ago #103218 by Maciej Charabin
Replied by Maciej Charabin on topic Re: SOLVED: Tutorial for extra fields?
Hi there,

I'm using this part of php code in my template. So I have title and subtitle (extra fields) in my k2 items.

I'd like to use it in this way:

Every item has a title and I want to display it on home page. So when user click on the main page and open k2 item, I'd like that he would see a subtitle from extra fields instead of item title. But when item has no subtitle (extra fields), he would see item title....

Maybe someone help..

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

More
10 years 8 months ago #103219 by JoomlaWorks
Replied by JoomlaWorks on topic Re: SOLVED: Tutorial for extra fields?
You will need to modify the item.php subtemplate in K2.

First read this on K2 templating in general: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Then edit your item.php file and locate the part where the title is shown. We'll add a small check so we can display the subtitle instead.

Create your subtitle extra field, add it to a group and make sure this group is also assigned to one or more categories in K2. Let's say this extra field is simply called "Subtitle" in which case, it will get the alias "Subtitle" as well. We will use this "alias" to directly fetch and display the subtitle value if it exists.

Find this (~line 54):
<?php echo $this->item->title; ?>

and replace with this:
<?php if($this->item->extraFields->Subtitle->value!=''): ?>
<?php echo $this->item->extraFields->Subtitle->value; ?>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>

This will check if the Subtitle extra field is set. If it is, it will display it, otherwise it will display the K2 item title.

Simple.

For more on this neat trick read the 2.6.2 release post: getk2.org/blog/1068-k2-v262-now-available

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

More
10 years 8 months ago #103220 by Maciej Charabin
Replied by Maciej Charabin on topic Re: SOLVED: Tutorial for extra fields?
YEAH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :)

You're the best! :)

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

More
10 years 8 months ago #103221 by Maciej Charabin
Replied by Maciej Charabin on topic Re: SOLVED: Tutorial for extra fields?
Hi :)

Only one question...

Code works perfectly, but now when we have subtitle (extrafields), so it displays on the item title position (that's OK) and also on the extra fields.

Maybe someone know, how to display this subtitle (extrafield) on item title and at the same time not display in the extra fields position...

This is extra field code from item php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
	  <!-- Item extra fields -->
	  <div class="itemExtraFields">
	  	<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
	  	<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; ?>">
				<?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>
	  </div>
	  <?php endif; ?>

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

More
10 years 8 months ago #103222 by JoomlaWorks
Replied by JoomlaWorks on topic Re: SOLVED: Tutorial for extra fields?
Under the foreach loop in PHP, do this (I'm only editing what's necessary - adapt as you wish):
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>

<?php if($extraField->name=='Subtitle') continue; ?>
...
<?php endforeach; ?>

This will cause the foreach loop to skip when it comes to a "Subtitle" extra field. ;)

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

More
10 years 8 months ago #103223 by Maciej Charabin
Replied by Maciej Charabin on topic Re: SOLVED: Tutorial for extra fields?
I've made it like this:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
	  <!-- Item extra fields -->
	  <div class="itemExtraFields">
	  	<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
	  	<ul>
			

<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->name=='Podtytul') continue; ?>
<?php endforeach; ?>




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

But extra field wchich namie is "Podtytul" still exist in extra fields position... :( Please help...

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 8 months ago #103224 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: SOLVED: Tutorial for extra fields?
You do need a second
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>

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