Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: BigMike82 on August 13, 2008, 12:46:33 AM

Title: How To: Customize Layout of Search Results
Post by: BigMike82 on August 13, 2008, 12:46:33 AM
Hi Everyone,

I have a specific search results layout in mind. If you could please have a look at the attachement. The columns with a red X through them are ones I'm trying to remove. In the Subject column, there is the portion below in a red box with redundant information, which I'm trying to remove. And, I'm also trying to change "Date Posted" to "Last Post".

Any ideas?

Thanks so much!

- Mike
Title: Re: How To: Customize Layout of Search Results
Post by: [SiNaN] on August 13, 2008, 04:23:33 AM
Okay, I'll give the whole edit.

Search.template.php

Find:

if (!empty($context['topics']))
{
echo '
<td width="4%"></td>
<td width="4%"></td>
<td width="56%">', $txt[70], '</td>
<td width="6%" align="center">', $txt['search_relevance'], '</td>
<td width="12%">', $txt[109], '</td>
<td width="18%" align="center">', $txt['search_date_posted'], '</td>';

if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
echo '
<td width="24" valign="middle" align="center">
<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="check" />
</td>';
elseif (!empty($options['display_quick_mod']))
echo '
<td width="4%" valign="middle" align="center"></td>';
}
else
echo '
<td width="100%" colspan="5">', $txt['search_no_results'], '</td>';
echo '
</tr>';

while ($topic = $context['get_topics']())
{
// Work out what the class is if we remove sticky and lock info.
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

echo '
<tr>
<td class="windowbg2" valign="top" align="center" width="4%">
<img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" /></td>
<td class="windowbg2" valign="top" align="center" width="4%">
<img src="', $topic['first_post']['icon_url'], '" alt="" align="middle" /></td>
<td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" valign="middle">
' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '<img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , '
' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '<img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" /><b>' : '' , $topic['first_post']['link'] , $topic['is_sticky'] ? '</b>' : '' , '
<div class="smalltext"><i>', $txt['smf88'], ' ', $topic['board']['link'], '</i></div>';

foreach ($topic['matches'] as $message)
{
echo '<br />
<div class="quoteheader" style="margin-left: 20px;"><a href="', $scripturl, '?topic=', $topic['id'], '.msg', $message['id'], '#msg', $message['id'], '">', $message['subject_highlighted'], '</a> ', $txt[525], ' ', $message['member']['link'], '</div>';

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

echo '
</td>
<td class="windowbg2" valign="top" width="6%" align="center">
', $topic['relevance'], '
</td><td class="windowbg" valign="top" width="12%">
', $topic['first_post']['member']['link'], '
</td><td class="windowbg" valign="top" width="18%" align="center">
', $topic['first_post']['time'], '
</td>';


Replace:

if (!empty($context['topics']))
{
echo '
<td width="80%">', $txt[70], '</td>
<td width="20%" align="center">', $txt[22], '</td>';

if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
echo '
<td width="24" valign="middle" align="center">
<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="check" />
</td>';
elseif (!empty($options['display_quick_mod']))
echo '
<td width="4%" valign="middle" align="center"></td>';
}
else
echo '
<td width="100%" colspan="5">', $txt['search_no_results'], '</td>';
echo '
</tr>';

while ($topic = $context['get_topics']())
{
// Work out what the class is if we remove sticky and lock info.
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

echo '
<tr>
<td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" valign="middle">
' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '<img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , '
' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '<img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" /><b>' : '' , $topic['first_post']['link'] , $topic['is_sticky'] ? '</b>' : '' , '
<div class="smalltext"><i>', $txt['smf88'], ' ', $topic['board']['link'], '</i></div>';

echo '
</td>
<td class="windowbg" valign="top" width="18%" align="center">
', $topic['last_post']['time'], '
</td>';
Title: Re: How To: Customize Layout of Search Results
Post by: BigMike82 on August 13, 2008, 09:51:21 AM
Wow, that's great. Thanks so much. I looked through the code, and see what you did, so I understand it better.

One thing, where you edit the txt values, for example: $txt[22]?

Thanks,
Mike
Title: Re: How To: Customize Layout of Search Results
Post by: [SiNaN] on August 13, 2008, 09:54:58 AM
Do not edit that. I took it from index.english.php. It stands for last post and used almost everywhere in forum. You can add your own string there and use it if you want.
Title: Re: How To: Customize Layout of Search Results
Post by: BigMike82 on August 13, 2008, 10:06:12 AM
SiNaN,

Thanks so much. You've been a real help. Learned a lot!

Got a few more mods I'm going to try and work out!

- Mike
Title: Re: How To: Customize Layout of Search Results
Post by: [SiNaN] on August 13, 2008, 10:08:36 AM
Inform us when you get it solved so that we can mark the topic as solved. You're always welcome. ;)
Title: Re: How To: Customize Layout of Search Results
Post by: BigMike82 on August 13, 2008, 10:09:53 AM
My original request has been solved. Thank you!
Title: Re: How To: Customize Layout of Search Results
Post by: Sakae on March 06, 2010, 11:22:22 AM
Sorry for bumping a very old topic, but I noted that Simple Machines search results has changed (test yourself and check it out).

But I'm not sure this code works for my SMF 2.0 RC2, so it's there any chance on updating this scratch?

Thanks in advance!