Tue15Jan2019
Information
Print

Add your own information types in Latest News Enhanced Pro

Information
Latest News Enhanced Pro
First published January 13, 2017
1479 hits -
 
Required:
Latest News Enhanced Pro module Latest News Enhanced Pro v2.5+
or Latest News Enhanced Pro component Latest News Enhanced Pro v4.6+
MyDetails plugin MyDetails

It is possible to add custom information for each individual item in Latest News Enhanced Pro, on top of the detailed information you can already show.

In order to do that, we can take advantage of 2 of the hooks (events) available in the extension.

First, we need to be able to add the field type in the list of fields available for output and second, we need to set how the output will present itself for each item.

With this tutorial, you will be able to add:

  • a field type that can render an article or K2 item title,
  • a field type that outputs a link,
  • a field type that outputs the meta description of an article or K2 item, if available,
  • a field type that can query a database table for getting a specific value,
  • New the Gravatar of the author (version for LNEP v4.6+ only).

Information types

Please download the sample code to use as a base for your own customizations.

For Latest News Enhanced Pro v2.5+, download:


For Latest News Enhanced Pro v4.6+, download:

You can use the plugin plg_latestnewsenhanced_mydetails as-is, but its usage will be limited.

The plugin can easily be internationalized by adding your own language files (in this case, mydetails.xml will need to be updated accordingly) or by creating language overrides.

Step 1 Install the plugin (not on a production site). It will be found under plugins/latestnewsenhanced/

Step 2 Open the plugin file mydetails.php. The code is documented with key information.

Step 3 Go to the method onLatestNewsEnhancedPrepareDetailSelection. This is the code that will be called whenever the select box containing all the information types is created.

Step 4 Add the name of the type you want to see as information type to the array of information types.

$information_types[] = '[information type]';

Note The information type is made of the plugin name _ the type. For instance : mydetails_title.

Step 5 Go to the method onLatestNewsEnhancedGetDetailData. This is the code that will be called whenever items are shown on the page. For parameter explanations, check the source code.

Step 6

LNEP 2.5+ Add the html code and data to the block that will be shown when selecting the information type. A classic output bloc will look like this:

if ($detail[0] == '[information type]') {
    $info_block = '<span class="detail detail_[information type]">';
    $info_block .= modLatestNewsEnhancedExtendedHelper::getPreData($detail[1], $detail[2], '[default icon]', $detail[3]);
    $info_block .= '<span class="detail_data">';
    $info_block .= '[content output]';
    $info_block .= '</span>';
    $info_block .= '</span>';
    return $info_block;
}

LNEP 4.6+ The output code is now placed into overridable layouts.
On plugin install, the sample layouts are moved to the Latest News Enhanced Pro extension (into /layouts/details). It is imperative that you place your new layouts there in order for them to be taken into account. You can override them in your template.

Layout files must follow the convention: lnep_detail_[plugin name]_[information_type].php

Note For the list of available icons, go to documentation/common-features/icon-picker-common.

Step 7 Save your code.

Step 8 Open the file en-GB.plg_latestnewsenhanced_mydetails.sys.ini.

Step 9 Add the key/value pair that corresponds to the information type that you have created. Follow the convention: PLG_LATESTNEWSENHANCED_[plugin name]_DETAIL_LABEL_[information type]

You will get the following output for this sample plugin:

Result

More information is available in the extension's documentation, under the Extend the extension section.