Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Query for search done in vanilla forums

edited August 2011 in Vanilla 2.0 - 2.8
when i search something in vanilla forums, can it be made possible that the search items returned are highlighted with the query text used ?


  • Options
    edited January 2012

    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 elements.

  • Options

    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.

    grep is your friend.

  • Options

    Yes definitely.

Sign In or Register to comment.