News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Limit lines per search result (shown as message)

Started by bitmovel, October 09, 2008, 03:11:22 PM

Previous topic - Next topic

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

ThorstenE

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

edit the Themes/default/Search.template.php

find:
$message['body_highlighted']

replace with..
substr($message['body_highlighted'],0,600)

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

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


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

1 teste
2 t


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

1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
10 test





any other solution?

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

$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];
}
}

Nathaniel

Find this code ('Themes/default/Search.template.php' file):
            if ($message['body_highlighted'] != '')
               echo '
               <div class="quote" style="margin-left: 20px;">', $message['body_highlighted'], '</div>';


Replace with this 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>';
                }


Change the '$num_lines = 7' value to change the max number of lines.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Advertisement: