Keyword

How to show extrafields in title on K2

More
5 years 9 months ago - 5 years 9 months ago #172898 by marek
Hello! I have tried several methods but they do not work

in the item.php file I added an extra field with price for the title,
but I would like to hide the price in additional information on this page.
see them: "Spam block"

also I want add price to tilte item in category view (category_item.php) but it don't work this same...

could somebody help me
Last edit: 5 years 9 months ago by marek.

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

More
5 years 9 months ago #172900 by JoomlaWorks
Replied by JoomlaWorks on topic How to show extrafields in tilte on K2
Try this first to call a single extra field anywhere: getk2.org/documentation/tips-a-tricks/2667-display-single-extra-fields-anywhere-in-your-k2-content

This applies to both item.php and category_item.php.

I did not really get the "spam block" comment you made.

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

More
5 years 9 months ago - 5 years 9 months ago #172903 by marek
Replied by marek on topic How to show extrafields in title on K2
my website is : automaz.fu2018.e-kei.pl/index.php/k2



If I have field with alias: Cena
I must change

echo $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->name; to
echo $this->item->extraFields->Cena->name;
or
echo $this->item->extraFields->CENA->name; ?

so, If I have in category_item.php :
<?php if($this->item->params->get('catItemTitle')): ?>
<!-- Item title -->
<h3 class="catItemTitle">
<?php if(isset($this->item->editLink)): ?>
<!-- Item edit link -->

<span class="catItemEditLink">
<a data-k2-modal="edit" href="<?php echo $this->item->editLink; ?>">
<?php echo JText::_('K2_EDIT_ITEM'); ?>
</a>
</span>
<?php endif; ?>

<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>

<?php else: ?>
<?php echo $this->item->title; ?>

<?php endif; ?>
<?php echo $this->item->extraFields->CENA->name;?><?php echo $this->item->extraFields->CENA->value;?>
<?php echo $extrafields[8];?> zł <?php echo $this->item->extraFields->CENA->value;?>

I don't see price on title

2.
How to hide extra fields Cena from additional information on
automaz.fu2018.e-kei.pl/index.php/k2/item/1-renaultscenic
?
I try this : gavick.com/blog/how-to-hide-selected-k2-extra-fields-from-the-front-end
and I don't see effects.
Attachments:
Last edit: 5 years 9 months ago by marek.

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

More
5 years 9 months ago #172915 by JoomlaWorks
Replied by JoomlaWorks on topic How to show extrafields in title on K2
Make the "alias" lowercase and call it like that:

echo $this->item->extraFields->cena->name; (for the name - Cena)
echo $this->item->extraFields->cena->value; (for the actual value, the price)

To hide a specific extra field from the extra fields loop, you need to add an exception there. E.g. in the current item.php file as seen here github.com/getk2/k2/blob/master/components/com_k2/templates/default/item.php#L250 you would change "value != ''): ?>" to "value != '' || $extraField->name != 'Cena'): ?>".

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

More
5 years 8 months ago - 5 years 8 months ago #172926 by marek
Replied by marek on topic How to show extrafields in title on K2
Thanks for reply, Show extrafields in title works ok! :) but hide someone extrafield no...

I change alias to lowercase and change :

<?php if($extraField->value != ''): ?> to <?php if($extraField->value != '' || $extraField->name != 'cena'): ?> but field cena is still show. Cena 17900
site automaz.fu2018.e-kei.pl/index.php/item/4-skoda-octavia

item.php looks now:
<?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 != '' || $extraField->name != 'cena'): ?>

<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?> alias<?php echo ucfirst($extraField->alias); ?>">
<?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; ?>
Last edit: 5 years 8 months ago by marek.

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

More
5 years 8 months ago #172943 by JoomlaWorks
Replied by JoomlaWorks on topic How to show extrafields in title on K2
Replace:
<?php if($extraField->value != '' || $extraField->name != 'cena'): ?>

with:
<?php if($extraField->value != '' && $extraField->name != 'cena'): ?>

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

More
5 years 8 months ago #172963 by marek
Replied by marek on topic How to show extrafields in title on K2
Thanks! With && works correct.

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

More
5 years 8 months ago #172974 by JoomlaWorks
Replied by JoomlaWorks on topic How to show extrafields in title on K2
Great.

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


Powered by Kunena Forum