How to pull only K2 items with image in Joomla module NEWS SHOW PRO GK5

Joomla is very popular CMS. I like to extend it with K2 CCK and one of the best modules, in my opinion, to diplay the K2 items is News Show Pro GK5 developed by GAVICK. It is very poweful module but I needed a way to display only the K2 items that has image.

Here is what I deed to achive this feature:

1. First we open the file: mod_news_pro_gk5.xml (it is located in /modules/mod_news_pro_gk5 folder) and around the line 262 we add this code:

<field name="k2_get_only_items_with_images" type="list" class="gk_switch" default="0" label="Show only items with images" description="With this option ON the module will get only the K2 items with image (the ones with image_credits field not empty!)">
<option value="1">Yes</option>
<option value="0">No</option>
</field>

2. After this open the file: /modules/mod_news_pro_gk5/data_sources/com_k2/model.php and do this:

around the line 237 add:

// only K2 items with image - helper variables
if($config['k2_get_only_items_with_images'] == 1) {
$onlyitemswithimage = ' AND content.image_credits !="" ';
} else if($config['k2_get_only_items_with_images'] == 0) {
$onlyitemswithimage = '';
}


after that, a few lines below there is a line that contains this code:

content.published = 1 AND content.trash = 0

change it do look like this:

content.published = 1 AND content.trash = 0'. $onlyitemswithimage .'

If it is everythink done properly we should have now in the backend panel of the module under the K2 setting the abitliy to choose if the module will show only the K2 items with image.

NOTE: actually this changes to the code will only display the K2 items wich field "image credits" is not empty. Since K2 does not write the infor about the image files in database the code to check if there really is a K2 image is a little bit complicated. But I guess that his can also do the trick :)

Be aware that with this instructions we hacked the core files of NEWS SHOW PRO GK5 module so if you update the module you should repeat the process.