Spice up your internal sNews CMS search page with result descriptions

Comments (10)

Here is a very simple way to add a nice extra touch to your internal sNews search results, by adding the meta description below each entry title. If you've ever noticed when doing a Google search, they will put the page's meta description just below the search title. This hack is super simple.


Step 1) As always, BACK-UP your snews.php file and work off a copy. Now find the function search and paste the two (scroll over if needed) following highlighted code snippets in the corresponding places;

$Or_id = implode(' OR ',$Or_id);
$query = 'SELECT
        title,a.seftitle AS asef,a.date AS date,
        c.name AS name,c.seftitle AS csef,
        x.name AS xname,x.seftitle AS xsef,a.description_meta AS description
    FROM '._PRE.'articles'.' AS a
    LEFT OUTER JOIN '._PRE.'categories'.' as c
        ON category = c.id
    LEFT OUTER JOIN '._PRE.'categories'.' as x
        ON c.subcat =  x.id
    WHERE '.$Or_id;
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
    $date = date(s('date_format'), strtotime($r['date']));
    if ($r['name']) $name = ' ('.$r['name'].')';
    if (isset($r['xsef']))  $link = $r['xsef'].'/'.$r['csef'].'/';
    else $link = isset($r['csef']) ? $r['csef'].'/' : '';
    echo '<p><a href="'._SITE.$link.$r['asef'].'/">'.$r['title'].$name.'</a> - '.$date.'<br />'.$r['description'].'</p>';

And boom goes the dynamite, you're done, and your results should now look something like below :)

Search meta descriptions
bookmark / share this: Bookmark and Share
rated 5/5 (3 votes)


10 comments

Add a new comment »

Poppoll Poppoll said:
Jun 3rd, 2009 at 5:15 pm

Thanks Matt
PP


Vic Vic said:
Jun 4th, 2009 at 1:06 pm

Yay, finally! Thanks :-)


Matt Matt said:
Jun 4th, 2009 at 7:11 pm

lol Vic :)

Almost too easy, huh? Soon, I'll also explain how to do the same in the tagsearch function in case someone can't figure it out.


Sven - Philippe Sven - Philippe said:
Jun 11th, 2009 at 2:47 am

Excellent! Bravo!


toolman toolman said:
Jun 22nd, 2009 at 5:28 am

Simply and nice :D
Good work, again ;)

One question. How to sort search results by Categories/Titles not by ID?
For example:

catA
- artAB
- artBA
catB
- artAB
- artCC

I have many same titles in different categories and standard sorting not looking fine.


Matt Matt said:
Jun 23rd, 2009 at 7:16 am

Toolman, personally, my search function is all hacked up and uses MySQL full-text search to return ranked results, but for what you're asking, you can do this.

On a default snews.php, function search, look for

$query = $query.' ORDER BY id DESC LIMIT '.$limit;

and change it to

$query = $query.' ORDER BY c.id DESC LIMIT '.$limit;

that will order by the category ids, not the article ids.


Patric Patric said:
Jan 25th, 2010 at 9:34 am

A goodie one... Thanks.


Tina Tina said:
Apr 7th, 2010 at 6:22 pm

nice, thank you matt :)


Tina Tina said:
Apr 7th, 2010 at 6:42 pm

Hi Matt,
just thinking a bit afterwards. you know what would be nice to have ... a paging function for the searchresults, so that you can get all results, instead of just the predifined limit. I know it's probably not in your interest at the moment, since you have a different search engine implemented here, but if you ever have "nothing to do" (lol) ...


Matt Matt said:
Apr 8th, 2010 at 7:26 am

Yeah, the default search for sNews is quite limited, hence my use of Sphider.

Adding pagination shouldn't be *too hard*. I will add it to the list of requests, if I ever do manage to get some free time. :)



Write a comment

* = required field

:

:

:

:

You may insert urls in plain text, urls will be automatically linkified for trusted users and on seasoned posts only. All first comments are moderated, so use your email if you want to be remembered.


Back to top