Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

Query for search done in vanilla forums

when i search something in vanilla forums, can it be made possible that the search items returned are highlighted with the query text used ?
Tagged:

Answers

  • Sorry this might be old post but I thought I would share. You can do this. First you need to have the search files in you theme folder, it is better behavior. Open the the results.php file and put the following function at the top:

    function search_excerpt_highlight($excerpt, $keywords) { $keys = implode('|', explode(' ', $keywords)); $excerpt = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight">\0</strong>', $excerpt); return($excerpt); }

    Then replace this:

    SliceString(Gdn_Format::Text($Row->Summary, FALSE), 250);

    by this:

    $excerpt = SliceString(Gdn_Format::Text($Row->Summary, FALSE), 250);
    echo search_excerpt_highlight($excerpt,$this->SearchTerm);
    

    Then you can use css to style the strong.search-highlight elements.

    sahotataran
  • x00x00 Don't PM about development, I'm not currently taking on clients MVP

    If you re going to do it hat way, at least copy it over to you theme, otherwise it is likely to get overwiten. Better still do it is plugin with hooks. Or non invasive javascript, for optimal performance.

    Don't PM about development, I'm not currently taking on clients.

    grep is your friend.

Sign In or Register to comment.