Keyword

how can i extract and extra field item?

  • Start Tech Hosting
  • Start Tech Hosting's Avatar Topic Author
  • Offline
  • New Member
More
13 years 11 months ago #88983 by Start Tech Hosting
how can i extract and extra field item? was created by Start Tech Hosting
How can i extra an extra field item based on the name if gave it  when i created it. I am new to K2 and php but what i have figured out so that the the extra field group is and array. this is also the additional info block on the standard k2 templateit looks like thisArray
(
[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.

More
13 years 11 months ago #88984 by william white

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

  • Start Tech Hosting
  • Start Tech Hosting's Avatar Topic Author
  • Offline
  • New Member
More
13 years 11 months ago #88985 by Start Tech Hosting
Replied by Start Tech Hosting on topic how can i extract and extra field item?
thanks but that does not help as i will be using this in a template override. not what i am looking for still searching the web to find how to extract an stdClass from an array maybe that might help me get to the next point i my development.

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

More
13 years 11 months ago #88986 by william white
Replied by william white on topic how can i extract and extra field item?
I have used the $ custom = statement in overrides and then extracted the value in the position i want before, its always in the same place unless you change the number of xtra fields, and should be in the same place if you only add a field.

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

  • Start Tech Hosting
  • Start Tech Hosting's Avatar Topic Author
  • Offline
  • New Member
More
13 years 11 months ago #88987 by Start Tech Hosting
Replied by Start Tech Hosting on topic how can i extract and extra field item?
ok that is true but i intend to share my work with this community and if I do it the way you say then it would not work for anyone right out the box with out them going in the template code and editing it. i this i found a way o will post my results after some test in a few but i really appreciate you trying to help.

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

  • Start Tech Hosting
  • Start Tech Hosting's Avatar Topic Author
  • Offline
  • New Member
More
13 years 11 months ago #88988 by Start Tech Hosting
Replied by Start Tech Hosting on topic how can i extract and extra field item?
you will be the first to see my new template and get a copy if you would like just for trying to help it was very much appreciated.

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

More
13 years 11 months ago #88989 by Jiliko.net
Replied by Jiliko.net on topic how can i extract and extra field item?
Alex, if what you want is to extract an item from the extrafields array, just make a foreach loop on this array and test the element value :
// 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.

More
13 years 11 months ago #88990 by gugabm
Replied by gugabm on topic how can i extract and extra field item?
Hello Olivier,
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
  • Start Tech Hosting's Avatar Topic Author
  • Offline
  • New Member
More
13 years 11 months ago #88991 by Start Tech Hosting
Replied by Start Tech Hosting on topic how can i extract and extra field item?
this oliver that really helped no i want to go one step further and extract your the url form the right not i cannot create a button as the link give area has text if you understand what i am say just want the raw url imputed buy user and nothing else. any ideas.

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

More
13 years 7 months ago #88992 by Pasquale Luisi
Replied by Pasquale Luisi on topic how can i extract and extra field item?
Hi all, is it possible to make it work with latest.php layout?

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.


Powered by Kunena Forum