Keyword

Display specific extra field in module position ?

  • Uldis
  • Uldis's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago - 11 years 7 months ago #103145 by Uldis
Hello,

I've been looking around forum for a solution, but it seems that this question hasn't been answered yet.

I'm looking for ways to display content of specific extra field in a module position.

I found this in k2 tips - link

So I tried using this code
Log in  or Create an account to join the conversation.

More
11 years 7 months ago #103146 by william white
Replied by william white on topic Re: Display specific extra field in module position ?
this getk2.org/extend/extensions/date/item/632-k2-split-content
does something similar to what you want very nicely.
You may be able to override it to show only what you want, or get the code from it to link a module with the current item

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

  • Uldis
  • Uldis's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #103147 by Uldis
Thank you for a fast reply.

I was just editing: my first post.

I'm actualy already using k2 split content to display 1 extra field in module position, but I need to display another extra field in diferent module position, k2 split content can only display all extra fields or none.

I tried using code mentioned above in k2 split content override as well, but that didn't work out for me.

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

More
11 years 7 months ago #103148 by william white
Replied by william white on topic Re: Display specific extra field in module position ?
Although i havent tried it, there is a box in the split content module to select az subtemplate.
You should be able to create a subtemplate for it, and change the foreach loop that displays extra fields to do what you want, and select the subtemplate in the module instance

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

  • Uldis
  • Uldis's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #103149 by Uldis
I tried doing that, but for some reason using this code
Log in  or Create an account to join the conversation.

More
11 years 7 months ago #103150 by william white
Replied by william white on topic Re: Display specific extra field in module position ?
You could try just using the built in foreach loop that starts on line 83 of default.php in the split content override
<?php foreach ($item->extra_fields as $extraField): ?>
<li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="moduleItemExtraFieldsLabel"><b><?php echo $extraField->name; ?></b></span>
<span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<br class="clr" />
</li>
<?php endforeach; ?>

and insert a condition to only print out the extra field you want

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

More
11 years 7 months ago - 11 years 7 months ago #103151 by william white
Replied by william white on topic Re: Display specific extra field in module position ?
Code that works in the split content override below. You can also use the | (or) if you want to show more than one extra field and can specify it by name
<?php foreach ($item->extra_fields as $extraField): ?>
 <?php if($extraField->name == "ExtraFieldName"): ?>
 <li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
 <span class="moduleItemExtraFieldsLabel"><b><?php echo $extraField->name; ?></b></span>
  <span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
     <br class="clr" />
    </li>
 <?php endif;?>
 <?php endforeach; ?>

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

  • Uldis
  • Uldis's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #103152 by Uldis
William,

thank you very much this is exactly what I wanted to achieve.

I don't know php yet, but I want to learn it very much.

Thank you for providing code I needed !

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

More
11 years 6 months ago - 11 years 6 months ago #103153 by Steven Johnson
Replied by Steven Johnson on topic Re: Display specific extra field in module position ?
Thanks so much for posting the foreach loop. I think this gets me on the right track.

What does the php code look like to insert a condition to print out a specific field?

Thanks! -- Steven

I am on Joomla 2.5.7 and K2 2.5.7


EDIT
After reading this post, I do not think this is 100% my situation. I am trying to display the k2 content module on the home page. In this module I want to display a single custom field for each of the different items

When I and the code to prepare extra field
Log in  or Create an account to join the conversation.

More
11 years 6 months ago #103154 by william white
Replied by william white on topic Re: Display specific extra field in module position ?
If you are using mod_k2_content you should create a subtemplate for the module and edit the built in foreach loop in default.tmpl/default.php to either display the field you want or hide the ones you do not want

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