Adding Images to Site Search Results

Both the flat file and database versions of my site search script now allow you to add images to the entries on the results page.

At this stage only pages that are contained in the same directory as the search script can have images attached. Any page that contains a slash(/) in the filename field will not display an image next to that entry if it appears in the results. For an entry to have an attached image the filename entry must be in the format filename.html, filename.htm, filename.php or similar. It doesn't matter what file extension that the filename has as long as the entry does not have a path qualification on the front of it.

To associate images with entries whose filenames match the above requirements you must first make sure that you have version 1.2 (or later) of the resinc.php file installed. You then add or update the $imgdir = '~'; entry in the config.php file to identify the directory where the images to associate with the results are located. If the images are in the same directory as the web pages then set $imgdir = '';. If the images are in a sub-directory of that directory then you need to specify that sub-directory name followed by a slash. For example if the images are in a sub-directory called image then you would set $imgdir = 'image/';.

For each entry in the results file where the filename of the web page does not have a path or domain name on the front (ie. doesn't contain a slash) the directory specified by the $imgdir parameter will be checked to see if it contains an appropriately named image to display with the entry. The filename of the web page without its extension will have .gif, .jpg, and .jpeg extensions added in turn and if an image file with this name is found in the directory specified in the $imgdir parameter then that image will be added at the front of the entry on the results page.

To give consistent output on the results page I suggest that all of the images that you set up to use with the results page of the search script should all have the same dimensions and the dimensions should not exceed 100 width and 100 height in order to leave room to the right of the image to properly display the page title, description, etc.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate