21295 Posts in 5734 Topics by 2602 members
| Go to End | ||
| Author | Topic: | 1730 Views |
-
Re: Remove images from search results

10 August 2010 at 2:09pm
Thanks Willr!
I no longer get an error message, however the search results still contain images, the code shows the same markup as the original search method.
Any ideas?
Thanks
D -
Re: Remove images from search results

17 August 2010 at 12:35pm
Hi Willr,
I've gone through this all with a fine tooth comb, have also double checked to ensure that the live site is working with the updated code. Unfortunately, the search results still include images
It would be great if we could nail this one as I have noticed a couple of other similar questions on the forum.
The problem images are included in the body content thusly:
<p><img blah blah>blah blah</p>
-
Re: Remove images from search results

17 August 2010 at 6:34pm
Oh sorry Stompit I didn't know you were referring to images inside the content. My code will only remove images from being searched as standalone assets. Removing images from posts is another kettle of fish.
A couple ways you could do it:
- The easiest way (and what I normally do) is display the results using $Content.NoHTML which will strip all the formatting / images / heading out.
- If you like formatting then a possible solution is to have a regular expression which replaces the image tags with nothing. I'm not a regular expression expert so would have no clue what the actual code to get that working but how you would do it would be to have a function in your Page class like
function NoImages() {
$content = $this->Content;return DBField::create('HTMLText', preg_replace("/<img[^>]+\>/i", " ", $content));
} -
Re: Remove images from search results

18 August 2010 at 8:28pm
Thanks again Willr
The saga continues...
Referring back to my original code there is no reference to $content, however I have tried to assign the .NoHTML to $form an a few other elements with no luck, keeps throwing errors. I am working with the page.php file.
Would I find the $Content in another file, or am I missing something obvious!?
Thanks
D -
Re: Remove images from search results

18 August 2010 at 8:47pm
Would I find the $Content in another file, or am I missing something obvious!?
This would be in your search results template. Page_results.ss or similar.
-
Re: Remove images from search results

20 August 2010 at 6:18pm
Hooraa! Modifying that template worked like a charm!!
I didn't end up using the .NoHTML, doing so produced a huge chunk of text in the results.
I had: $Content.FirstParagraph(html) which I changed to $Content.FirstParagraph, seemed to do the job
Thanks a million for all your help!
Best Regards
D
| 1730 Views | ||
| Go to Top |

