Welcome! Log In Create A New Profile

Advanced

Sphider with Product Images in results page

Posted by erussell 
Sphider with Product Images in results page
April 05, 2012 11:13PM
For those of you who are looking to put images next to your sphider results...
I use Sphider for indexing a product folder with thousands of items, here is an example of my file structure for use with this snippet:

www/

product/
item1.php
item2.php
item3.php

images/
item1.png
item2.png
item3.png

Insert this into sphider/templates/standard/search_results.html (or sphider/templates/dark/search_results.html) in line 75 just after <a href="<?php print $url?>" class="title">
<?PHP
        // Edit here
          $url_path = "http:// www.yoursite.com/product/";    // The url leading to your indexed pages.
          $url_ext = ".php";                                     // The file extension of indexed pages.
          $image_path = "../images/";                              // Path to image folder.
          $image_ext = ".png";                                       // The file extension of images.
        // To here

        $image = str_replace("$url_path", "$image_path", $url);
        $image = str_replace("$url_ext", "$image_ext", $image);
        if (file_exists($image)) { // Do nothing
	} else { $image = $image_path . "ICS" . $image_ext; } ?>
        <img src="<?PHP print $image ?>" alt="" align="left" style="margin-right:10px; border:0;" />

Basically, if you have a page called 1234.php in your Sphider index, this will try to find picture 1234.png to go along side it of the search result. If an image is not found it will display a default image 'ICS.png' (Image Coming Soon).

Happy coding smileys with beer
Sorry, only registered users may post in this forum.

Click here to login