Keyword
Please note that official support for commercial extensions & templates is provided in the Subscriber Help Desk.
Support requests should ONLY be directed there and require an active subscription plan.
This forum board is to be used for archive purposes and knowledge exchange ONLY.

[HACK] Use K2 extra fields in slides

  • Marjorie COULIN
  • Marjorie COULIN's Avatar Topic Author
  • Offline
  • New Member
More
12 years 8 months ago - 12 years 8 months ago #42390 by Marjorie COULIN
[HACK] Use K2 extra fields in slides was created by Marjorie COULIN
Well, I did it.

If it can be of any use to somebody else, I'll tell here what to do.
It is quite home-made and not optimized at all, but it works.

First, if you want the extra fields visibility to be configurable, add these lines in mod_fpss/mod_fpss.xml
(By default, visibility will be set to No)
<param name="extra_fields" type="list" default="" label="FPSS_EXTRA_FIELDS" description="FPSS_SHOW_OR_HIDE_THIS_ELEMENT_IN_THE_SLIDESHOW">
<option value="0">FPSS_NO</option>
<option value="1">FPSS_YES</option>
</param>

Add also the right string in languages/en-GB/en-GB.mod_fpss.ini
FPSS_EXTRA_FIELDS="Extra fields"


Then you'll have to retrieve these extra-fields from the database for each article from the category.
Complete the SQL request in com_fpss/helpers/slideshow.php, ~line 197
$query = "SELECT item.title, item.introtext, item.extra_fields, item.catid, item.alias,[...]
and add the extra-fields to the slide data, ~line 224
$slide->extra_fields = json_decode($row->extra_fields);
The "extra_fields" DB field is a text field that contains all the extra fields. It is encoded using JSON encoding.
The json_decode PHP function parses the field content into an array of extra fields headed "id" and "value".


Finally you may want to use the extra-fields stored in the slides data...
The following is an example built from what I wanted to do.
I wanted to print a specific extra-field as a subtitle on each slide. This extra-field had the id 36 in K2 > Extra Fields > "id" column

I thus added this piece of code in the slideshow template's default.php, between the slidetext divs, right under the title:
<?php if($slide->params->get('extra_fields')): ?> <- this only if a parameter was defined in mod_fpss.xml
<?php $extraFields = $slide->extra_fields; ?>
<?php foreach ($extraFields as $key=>$extraField):?>
<?php if ($extraField->id == '36'): ?><h1><?php echo $extraField->value; ?></h1><?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
It runs across all the extra-fields stored in the slide data to find the right id, then prints it once found.

Went lazy when trying to associate id and extra-field name, so I use it as it is and that's not so bad.
The topic has been locked.

Powered by Kunena Forum