-
AuthorPosts
-
January 26, 2011 at 6:31 am #159323
Hi. Just wondering if it’s possible to show the k2 item image on the JA K2 Search Module Results Page.
We’re using the module to search products and would like customers to see the product image on the search results page so they can easily identify the product.
Any ideas?
Thanks so much
Emthuanlq Friendthuanlq
- Join date:
- October 2010
- Posts:
- 528
- Downloads:
- 0
- Uploads:
- 29
- Thanks:
- 8
- Thanked:
- 121 times in 99 posts
February 1, 2011 at 1:59 pm #374750HI
I tried your solution but it doesn’t look like the results class is returning an image
In <img src=”<?php echo $result->image; ?>” alt=”<?php echo $result->title; ?>” title=”<?php echo $result->title;?>” width=”100px” height=”100px”/>
$result->image is empty
My site is here
http://www.farmhousesaleslemarcheitaly.co.uk/
If you search on province and select fermo there are 2 results in there
It’s critical that I can show the images next to the search results so any help would be really appreciated.
Many thanksMark
February 4, 2011 at 12:53 am #375025directly call the k2 database in the default_results.php
February 7, 2011 at 5:36 pm #375421I too tried this with no luck. Also how do I call the database? Thanks
thuanlq Friendthuanlq
- Join date:
- October 2010
- Posts:
- 528
- Downloads:
- 0
- Uploads:
- 29
- Thanks:
- 8
- Thanked:
- 121 times in 99 posts
February 10, 2011 at 9:25 am #376003Hi all,
To call the k2 item images on search page directly, please do try as following:
– Open “default_results.php” file in the folder “com_searchviewssearchtmpl” and add custom code
$db = JFactory::getDBO();
$query = "
SELECT i.id,i.title,
i.metadesc,
i.metakey,
c.name as section,
i.image_caption,
i.image_credits,
i.video_caption,
i.video_credits,
i.extra_fields_search,
i.created,
CONCAT(i.introtext, i.fulltext) AS text,
CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(':', i.id, i.alias) ELSE i.id END as slug,
CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as catslug
FROM #__k2_items AS i
INNER JOIN #__k2_categories AS c ON c.id=i.catid
WHERE i.id = ". $result->id;
$db->setQuery($query);
$item = $db->loadObject();
– Or please download my attach file and extract to your web root, it override “default_results.php” and “plugins/search/jak2_filter.php” files.
11135
1 user says Thank You to thuanlq for this useful post
February 14, 2011 at 3:02 pm #376654It works for me – thank you 🙂
May 13, 2011 at 1:08 pm #391090did not work for me, don’t know why
June 30, 2011 at 1:58 pm #399350Hi,
It works also for me but i’d like to show 2 search results every line. How to do it?
Thank yourelevanceweb Friendrelevanceweb
- Join date:
- May 2011
- Posts:
- 11
- Downloads:
- 0
- Uploads:
- 1
- Thanks:
- 2
- Thanked:
- 1 times in 1 posts
July 13, 2011 at 12:31 pm #400963This works for me, but it’s better to use a template override rather than replace the com_search file directly.
For those of you who couldn’t get it working, have a look in your template folder to see if there is already an override there
/html/com_search/search/default_results.php1 user says Thank You to relevanceweb for this useful post
February 17, 2012 at 12:19 am #438631I am getting the same problem – it looks like $result->id is empty, hence the db query is not returning anything to $item. Did you work out the cause of this?
February 17, 2012 at 1:19 am #438633Finally solved this one.
I added print_r($result) to the foreach loop to check the contents of the $result array. Noticed there is no key with the name of id, so this is a problem because it is being referenced in the database query ($result->id). The query returns no result, and $item is empty.
What does this mean? Well, if $item is empty, the if condition if(!empty($item)) returns false and $image therefore does not get set to the url of the image. It remains an empty string after being initialised at the beginning of the foreach loop.
The solution? Change the database query to reference $result->key1 since key1 in the array is the id. It is possible the replacement for jak2_filter.php provided in an earlier post in this thread has been updated to reflect this, but it didn’t work in my case, and I was reluctant to pick through yet another haystack.
It is also worth checking the url being referenced for $image exists in your setup of K2. I have altered the way K2 generates files so only small and large image files are created. I therefore had to change $arr_k2image[“imageGeneric”] to $arr_k2image[“imageSmall”].
The amended foreach loop looks like the following:
[PHP]foreach( $this->results as $result ) : ?>
<?phpif(isset($result->extra_fields_search))
{
$query = “
SELECT i.id,i.title,
i.metadesc,
i.metakey,
c.name as section,
i.image_caption,
i.image_credits,
i.video_caption,
i.video_credits,
i.extra_fields_search,
i.created,
CONCAT(i.introtext, i.fulltext) AS text,
CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(‘:’, i.id, i.alias) ELSE i.id END as slug,
CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(‘:’, c.id, c.alias) ELSE c.id END as catslug
FROM #__k2_items AS i
INNER JOIN #__k2_categories AS c ON c.id=i.catid
WHERE i.id = “.$result->key1;
$db->setQuery($query);
$item = $db->loadObject();
if(!empty($item))
{
$arr_k2image = getK2Images($item);
$image = isset($arr_k2image[“imageSmall”])?$arr_k2image[“imageSmall”]:””;}[/PHP]
February 17, 2012 at 10:59 pm #438729Should also point out you can condense the code above, depending on what you want to display in the results:
[PHP]
<?php
$db = JFactory::getDBO();
foreach( $this->results as $result ) : ?>
<?php
$item = $result->key1;
if(!empty($item))
{
$arr_k2image = getK2Images($item);
$image = $arr_k2image[“imageSmall”];
}
?>
[/PHP]This removes the sql query which I cannot see any need for, and will return the image for each item, as long as you change the getK2Images($item) function at the beginning of default_results.php to reference $item as a single variable rather than an array:
[PHP] function getK2Images($item)
{
jimport(‘joomla.filesystem.file’);
//Image
$arr_return = array();if (JFile::exists(JPATH_SITE.DS.’media’.DS.’k2′.DS.’items’.DS.’cache’.DS.md5(“Image”.$item).’_S.jpg’))
$arr_return[‘imageSmall’] = JURI::root().’media/k2/items/cache/’.md5(“Image”.$item).’_S.jpg’;return $arr_return;
}[/PHP] -
AuthorPosts
This topic contains 13 replies, has 10 voices, and was last updated by ochilstudio 12 years, 9 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum