Keyword

Custom display extra fields

  • Astrid Pedersen
  • Astrid Pedersen's Avatar Topic Author
  • Offline
  • New Member
More
9 years 8 months ago #131285 by Astrid Pedersen
Custom display extra fields was created by Astrid Pedersen
Hi,

is there anyone in here who has experience with custom displaying extra fields?

For instance: steffenjungersen.moloch.dk/

1. I want the "Karakter" (rating) field to display as a number of stars. The field is a dropdown field, where my client can choose from 1-6

2. I want "Info" to show beneath the title (Mastodon come of age)

3. I want to have other extra fields (photo, setlist etc) but I don't want them to show up in the category item view, only in the full item view.

Maybe there is an extension to customizing these views - or someone could point me in the right direction?

Thanks!

Aztrid

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

  • Astrid Pedersen
  • Astrid Pedersen's Avatar Topic Author
  • Offline
  • New Member
More
9 years 8 months ago #131286 by Astrid Pedersen
Replied by Astrid Pedersen on topic Re: Custom display extra fields
Okay. I got some help from a friend. Here's how far it got us (if anyone should wonder).

In order to have the extra fields displayed independently, you need to split them up. So replace the "foreach ..." line in you item.php with this:

<!-- START: Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
<!-- END: Call to prepare extra fields -->

Then, to call the extra field you need in, do this:

<?php if(isset($extrafields[*X*]) === true):?>
<?php echo $extrafields[*X*]; ?>
<?php endif; ?>

Where *X* is the numeric ID of the extra field.

Now here comes the fun part. I wanted to create a 1-6 stars rating system for my client who is a music journalist. He should be able to select a rating from a dropdown, and this value should be displayed as stars in the item view.

I decided to use the css and sprite based article rating system which comes with K2 - then I could "recycle" the nice star images and the css already created.

Heres how it looks:

<?php if(isset($extrafields[3]) === true):?>

<ul class="itemRatingList">
<li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo round($extrafields[3]*100/6); ?>%;"></li>
<li><?php if(isset($extrafields[3]) == 1):?><a href="#" title="<?php echo JText::_('K2_1_STAR_OUT_OF_5'); ?>" class="one-star">1</a></li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 2):?><a href="#" title="<?php echo JText::_('K2_2_STARS_OUT_OF_5'); ?>" class="two-stars">2</a></li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 3):?><a href="#" title="<?php echo JText::_('K2_3_STARS_OUT_OF_5'); ?>" class="three-stars">3</a></li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 4):?><a href="#" title="<?php echo JText::_('K2_4_STARS_OUT_OF_5'); ?>" class="four-stars">4</a></li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 5):?><a href="#" title="<?php echo JText::_('K2_5_STARS_OUT_OF_5'); ?>" class="five-stars">5</a></li><?php endif; ?>
<li><?php if(isset($extrafields[3]) == 6):?><a href="#" title="<?php echo JText::_('K2_6_STARS_OUT_OF_5'); ?>" class="six-stars">6</a></li><?php endif; ?>
</ul>

<?php endif; ?>

When I at some point can manage to get my hands down, I will look into replacing the a tags with span or something. But now it works.

Best regards,

Astrid

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


Powered by Kunena Forum