- Posts: 6
COMMUNITY FORUM
how can i extract and extra field item?
- Start Tech Hosting
-
Topic Author
- Offline
- New Member
(
[0] => stdClass Object
(
[id] => 1
[name] => RapidShare Link
[value] => Rapid Share
[type] => link
[group] => 1
[published] => 1
[ordering] => 1
)
[1] => stdClass Object
(
[id] => 2
[name] => authour
[value] => me
[type] => textfield
[group] => 1
[published] => 1
[ordering] => 2
)
[2] => stdClass Object
(
[id] => 3
[name] => Version
[value] => 45
[type] => textfield
[group] => 1
[published] => 1
[ordering] => 3
)
)
i need to just get the first one but based on the name but it may not always be the first on and display it in my template so that when there is a extra field called RapidShare Link it will show.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
community.getk2.org/forum/topics/using-extra-fields-with-a?commentId=3536014%3AComment%3A66945
Please Log in or Create an account to join the conversation.
- Start Tech Hosting
-
Topic Author
- Offline
- New Member
- Posts: 6
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.
- Start Tech Hosting
-
Topic Author
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- Start Tech Hosting
-
Topic Author
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- Jiliko.net
-
- Offline
- Platinum Member
- Posts: 567
// Code
foreach($myExtraFields as extraField) {
if ($extraField->value == 'myValue) {
$goodExtraField = $extraField;
break;
}
}
...Do what you want with $goodExtraField
//Code
Olivier
Please Log in or Create an account to join the conversation.
- gugabm
-
- Offline
- New Member
- Posts: 7
I think this solution you posted above is very close to what I need: I'm trying to call a especific extraFields and insert it on a HTML code I inserted in item.php.
But I`m new in PHP and K2, so would you mind help me in the details?
I understood that this code you posted above is supposed to replace this other in templates/default/item.php, at 253 line (or something close, my lines may have been changed after some editions):
//Code
foreach ($this->item->extra_fields as $key=>$extraField)
//Code
Is this?
If I'm right, how can I customize properly the code you posted? I mean, may I replace "$myExtraFields " with the name I gave to my extraField group? Then, what I exactly supposed to use has "myValue"? The name of a extraField created in a group? Thank you in advanced.
Please Log in or Create an account to join the conversation.
- Start Tech Hosting
-
Topic Author
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- Pasquale Luisi
-
- Offline
- New Member
- Posts: 9
Frank said:
Thanks for the advice. I was also working on extracting only certain extra fields and surprisingly it works! Below is my code for those who still need a more concrete version:
//Code <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <?php if($extraField->name == 'Ort'): ?> <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; ?>
//Code
Please Log in or Create an account to join the conversation.
- bournaud
-
- Offline
- New Member
- Posts: 2
it works fine with one group of extra fields on one template (templatejoomla\html\com_k2\templates\nametemplate1) (> dev.feteduconte.agglo-sqy.fr/index.php/programme)
but it does'nt work with an other group of extra fields on an other template (templatejoomla\html\com_k2\templates\nametemplate2) (> dev.feteduconte.agglo-sqy.fr/index.php/bibliographie)
the nametemplate2 is recognized but he does'nt extract the extra fields...
Please how can i do ?
ThanksFrank said:
Thanks for the advice. I was also working on extracting only certain extra fields and surprisingly it works! Below is my code for those who still need a more concrete version:
//Code<?php foreach ($this->item->extra_fields as $key=>$extraField):?> <?php if($extraField->name == 'Ort'): ?> <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; ?>
//Code
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
is referring to an extra field with the name of Ort. If you have two groups of extra fields they will probably have different names
bournaud said:
Thanks for this code, but i have a little problem :
it works fine with one group of extra fields on one template (templatejoomla\html\com_k2\templates\nametemplate1) (> dev.feteduconte.agglo-sqy.fr/index.php/programme)
but it does'nt work with an other group of extra fields on an other template (templatejoomla\html\com_k2\templates\nametemplate2) (> dev.feteduconte.agglo-sqy.fr/index.php/bibliographie)
the nametemplate2 is recognized but he does'nt extract the extra fields...
Please how can i do ?
ThanksFrank said:
Thanks for the advice. I was also working on extracting only certain extra fields and surprisingly it works! Below is my code for those who still need a more concrete version:
//Code<?php foreach ($this->item->extra_fields as $key=>$extraField):?> <?php if($extraField->name == 'Ort'): ?> <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; ?>
//Code
Please Log in or Create an account to join the conversation.
- bournaud
-
- Offline
- New Member
- Posts: 2
if($extraField->name == 'Ort'): ?>
is referring to an extra field with the name of Ort.
> yes i know that (dev.feteduconte.agglo-sqy.fr/index.php/programme)
If you have two groups of extra fields they will probably have different names
> yes my extra fields have different name and i change the name but they does'nt appear in my second template. I must specify the name of the group in the code ? how ?
Please Log in or Create an account to join the conversation.
- Jeff Whitmore
-
- Offline
- Junior Member
- Posts: 24
Please Log in or Create an account to join the conversation.