Keyword

Extra Field in Item view in cat. listings

  • Goble002
  • Goble002's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 7 months ago #164336 by Goble002
Hi,

is it possible to choose which extra field to appear when item is displayed in category listings ?

I'm also using JA K2 Filter, there I can choose which extra field to display in the search results.

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

More
6 years 7 months ago - 6 years 7 months ago #164337 by william white
Replied by william white on topic Extra Field in Item view in cat. listings
You can create an override and replace the extra field loop with references to a single extra field
see Krikors cheatsheet github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L90-L99
line 168

You can also get inside the loop and test for the name of an extra field or fields to show only the ones that pass the test
Last edit: 6 years 7 months ago by william white.

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

  • Goble002
  • Goble002's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 7 months ago - 6 years 7 months ago #164343 by Goble002
Replied by Goble002 on topic Extra Field in Item view in cat. listings
Hello and many thanks,

I really don't know anything about php (or very little).

I previously had to use override to display numeric values with Thousand separators (commas).
So I changed
<?php echo $extraField->value; ?>
to
<?php if (is_numeric($extraField->value)) {echo number_format($extraField->value);}
else
{echo $extraField->value;}?>

What I just achieved (after 3h) and glad it's working is below. Am sure there's a better way to achieve the same result but anyway.
<?php if (8==($extraField->id)) {echo '<span class="catItemExtraFieldsLabel">' .$extraField->name. '</span>';echo $extraField->value;} ?>
<?php if (7==($extraField->id)) {echo '<span class="catItemExtraFieldsLabel">' .$extraField->name. '</span>';echo number_format($extraField->value);} ?>
<?php if (12==($extraField->id)) {echo '<span class="catItemExtraFieldsLabel">' .$extraField->name. '</span>';echo number_format($extraField->value);} ?>
Last edit: 6 years 7 months ago by Goble002. Reason: Clean up Code

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 7 months ago #164353 by Krikor Boghossian
Replied by Krikor Boghossian on topic Extra Field in Item view in cat. listings
I would change (8==($extraField->id)) to:
($extraField->id === 8)
if it doesn't work try with ==

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

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

  • Goble002
  • Goble002's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 7 months ago #164360 by Goble002
Replied by Goble002 on topic Extra Field in Item view in cat. listings
Many thanks Krikor,

However forgot to mention that the IDs of the extrafields that I don't want ton appear here are 16,14,13,10,11,9. So it seems that it won't do the trick, right ? ;-)

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

More
6 years 7 months ago #164362 by william white

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


Powered by Kunena Forum