test
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • emp123 Friend
    #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
    Em

    thuanlq Friend
    #373984

    Dear @emp123,
    You can show k2 item image on search result page of ja k2 search module. I had to hard code to do it, please extract and copy my attach file into your webroot. Then, please add new style for result page as you want.
    10892


    vtsdesign Friend
    #374750

    HI

    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 thanks

    Mark

    virteer Friend
    #375025

    directly call the k2 database in the default_results.php

    jbravo8212 Friend
    #375421

    I too tried this with no luck. Also how do I call the database? Thanks

    thuanlq Friend
    #376003

    Hi 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


    ohzsolt Friend
    #376654

    It works for me – thank you 🙂

    doublit Friend
    #391090

    did not work for me, don’t know why

    yayo76 Friend
    #399350

    Hi,
    It works also for me but i’d like to show 2 search results every line. How to do it?
    Thank you

    relevanceweb Friend
    #400963

    This 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.php

    ochilstudio Friend
    #438631

    I 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?

    ochilstudio Friend
    #438633

    Finally 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 ) : ?>
    <?php

    if(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]

    ochilstudio Friend
    #438729

    Should 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]

Viewing 13 posts - 1 through 13 (of 13 total)

This topic contains 13 replies, has 10 voices, and was last updated by  ochilstudio 12 years, 10 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum