SMF Support > SMF 2.0.x Support

Limit lines per search result (shown as message)

(1/1)

bitmovel:
Hi

I use "show results as message" by default in my forum

but there are some big messages that makes the search results huge.

how can I limit search results to 5 lines each result?

Best Regards

TE:
not lines, but you can limit the search result by using php substr

edit the Themes/default/Search.template.php

find:

--- Code: ---$message['body_highlighted']
--- End code ---

replace with..

--- Code: ---substr($message['body_highlighted'],0,600)
--- End code ---

0,600 means output of the first 600 characters from each message

bitmovel:
thank you for your help.

but in fact that is useless.

if a post says


--- Code: ---1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
10 test
11 test
12 test
13 test
14 test
--- End code ---

i want to limit to 10 lines , and not to 10 chars, or else it would return:


--- Code: ---1 teste
2 t
--- End code ---

but what i really need is this result (cutting 10 lines)


--- Code: ---1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
10 test
--- End code ---




any other solution?

i found this code on google. I cannot adapt it to SMF. Could youtry it?


--- Code: ---$contents = file_get_contents('http://example.com/weather.html');
$array = explode("\n", $contents);
if(count($array) > 389){
for($i = 386; $i < 392; $i++){
echo $array[$i];
}
}
--- End code ---

Nathaniel:
Find this code ('Themes/default/Search.template.php' file):

--- Code: ---            if ($message['body_highlighted'] != '')
               echo '
               <div class="quote" style="margin-left: 20px;">', $message['body_highlighted'], '</div>';
--- End code ---

Replace with this code:

--- Code: ---                if ($message['body_highlighted'] != '')
                {
                    $body_array = explode('<br />', $message['body_highlighted']);
                    $num_lines = 7;
                    $i = 0;
                    $message['body_highlighted'] = '';
                    while($i < $num_lines && isset($body_array[$i]))
                    {
                        $message['body_highlighted'] .= $body_array[$i] . '<br />';
                        $i++;
                    }
                    $message['body_highlighted'] = substr($message['body_highlighted'], 0, -6);
                    echo '
                    <div class="quote" style="margin-left: 20px;">', $message['body_highlighted'], '</div>';
                }
--- End code ---

Change the '$num_lines = 7' value to change the max number of lines.

Navigation

[0] Message Index

Go to full version