Are you enjoying the extensions? Did you like the support? Help others decide.

Leave a review
27Mar2023
Information
Print

Add your own information types in Latest News Enhanced Pro

Information
First published January 13, 2017
7389 hits -
 

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,
  • the Gravatar of the author (version for LNEP v4.6+ only).
  • New the length of a YouTube video when the head type is a YouTube video (version for LNEP v4.9+ only).

For this tutorial, you need:

Information types
The additional information types

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_[information_type].php

Note For the list of icons you can use as default for your type, 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.