Best Answer Kess , 02 October 2014 - 05:57
Hello,
I think the easiest way is to make some small modifications to the jbimage element.
Here is one way to do it:
In the file
/media/zoo/applications/jbuniversal/elements/jbimage/jbimage.php
find the _getDefaultImage function and add these lines at the top:
$item = $this->getItem(); $mainCat = $item->getPrimaryCategory(); $mainCatImgPath = $mainCat->params->get('content.category_teaser_image', '');
and find this block of code:
if (strpos($imagePath, 'http') !== false) { $result = $imagePath; } else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) { return $this->app->jbimage->resize($imagePath, $width, $height); } else { $result = $this->app->jbimage->placeholder($width, $height); }
and add one more condition so it will look like this:
if (strpos($imagePath, 'http') !== false) { $result = $imagePath; } else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) { return $this->app->jbimage->resize($imagePath, $width, $height); } else if (JFile::exists($mainCatImgPath) || JFile::exists(JPATH_ROOT . '/' . $mainCatImgPath)) { return $this->app->jbimage->resize($mainCatImgPath, $width, $height); } else { $result = $this->app->jbimage->placeholder($width, $height); }
That's seems to be enough.
Now go to the elements configuration of your item type and enable default image option for you image element while leaving its path blank. Now it will use the primary category image of your items.
Go to the full post