You are here:  » HTML in search results


HTML in search results

Submitted by badger on Thu, 2006-07-27 08:54 in

Hi David.

I having a problem when i add HTML into a filter. For example, if i add a text after filter to append a field to the end of the product description, like so, %home delivery%. The filter works great, however on the search results page, if the text limit gets reached after the open DIV and before the closing DIV the page layout breaks. I could use tags but if i have 10 fields to append, and a certain product doesnt have anything in thoes fields, ill have a row of 10 tags. Would it be possible to remove the text after filter from only the description on the search results page?

Thanks

Submitted by support on Thu, 2006-07-27 09:15

Hiya,

What I would suggest in this scenario would be a modification to html/searchresults.php that automatically crops the description at the first occurance of the opening DIV tag; followed by the 250 character crop.

Currently, the description is displayed with the following code:

<p><?php print substr($product["description"],0,250); ?></p>

What you could do is this:

<p>
<?php
if (strpos($product["description"],"<DIV"))
{
  $product["description"] = substr($product["description"],0,strpos($product["description"],"<DIV"));
}
print substr($product["description"],0,250);
?>
</p>

The only other alternative would be to create a new field on the database to hold the description snippet and modify the search system to use the new field rather than the main description field - but that would quite a lot more code than this work around.

Cheers,
David.

Submitted by badger on Thu, 2006-07-27 09:53

cropping it at the sign of the first DIV sounds great, thanks

Submitted by badger on Thu, 2006-07-27 21:22

Just incase anyone else is looking to do this. Try this code instead:

<p>
<?php
if (strpos($product["description"],"<"))
{
  $product["description"] = substr($product["description"],0,strpos($product["description"],"<DIV"));
}
print substr($product["description"],0,250);
?>
</p>

i just replaced <DIV with <