Keyword

Pull a specific k2 extra field from News Show SP2 module

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
8 years 3 months ago #155244 by oshyne
The code below is from News Show SP2 module and shows all the extra fields assigned to a particular k2 extrafield group; please, i wish to know how to modify this code to display a specific extrafield from the array.

Your help and concern is highly appreciated!!!

Thanks


<?php /*K2 Extra fields*/ if ($article_extra_fields && $content_source == 'k2' && count($list[$i]->extra_fields)): ?>
<div style="clear:both"></div>

<div class="NS2K2ExtraFields">
<b><?php echo JText::_('Additional Info'); ?></b>

<ul>
<?php foreach ($list[$i]->extra_fields as $key=>$extraField): ?>
<li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?> <?php echo strtolower($extraField->name) ?> <?php echo $key%2 ? 'even' : 'odd';?> <?php if ($key==0) echo 'first'; ?>">
<span class="label"><?php echo $extraField->name; ?></span>
<span class="value"><?php echo $extraField->value; ?></span>

<div style="clear:both"></div>
</li>
<?php endforeach; ?>
</ul></div>
<div style="clear:both"></div>
<?php endif; ?>

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155433 by Krikor Boghossian
Replied by Krikor Boghossian on topic Pull a specific k2 extra field from News Show SP2 module
Generally, the code for displaying a specific extrafield in K2 is this:
github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L105-L109

I do not know how it should be ported for the News Show SP2 though.
You can try by replacing $this->item-> with $list[$i].

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

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

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
8 years 3 months ago #155499 by oshyne

Krikor wrote: Generally, the code for displaying a specific extrafield in K2 is this:
github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L105-L109

I do not know how it should be ported for the News Show SP2 though.
You can try by replacing $this->item-> with $list[$i].



Thanks and I really appreciate your help!

If this is what you meant:

<?php if( isset( $list[$i]->extraFields->price->value ) && ( $list[$i]->extraFields->price->value !== '') )
{
$list[$i]->extraFields->price->name;
$list[$i]->extraFields->price->value;
}

?>

I tried it but no values are returned.

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

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
8 years 3 months ago #155501 by oshyne
In the beginning of the codes that outputs the extrafields, I see this code:

<?php /*K2 Extra fields*/ if ($article_extra_fields && $content_source == 'k2' && count($list[$i]->extra_fields)): ?>

To my understanding, it test and confirms that K2 content source is enabled and then goes ahead to create a variable which
will display the extrafields in a list.

Please, is there a way to modify the code in bold so that it will display a specific extrafield instead of the whole list?

You can still take a look at the full codes above from New show sp2 module.

I am still trying to learn PHP.

Thanks in advance!!!!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155522 by Krikor Boghossian
Replied by Krikor Boghossian on topic Pull a specific k2 extra field from News Show SP2 module
Since this code is specific to that module, you should address this issue to the module's developer.

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

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


Powered by Kunena Forum