Spice up your internal sNews CMS search page with result descriptions
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 :)
Comments
RSS Comments Feed
Poppoll
PP
Vic
Matt
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
toolman
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
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 <span class="highlight">c.</span>id DESC LIMIT '.$limit;
that will order by the category ids, not the article ids.
Patric
Tina
Tina
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
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. :)
Gerry MacOstair
To give the search results a bit of "HTML5/Semantic code" flair, replacing the paragraphs with a description list were the decent thing to do, actually.
I'm too lazy to play "try and fail" with the comment editor until the code would display properly. If you are interested, give me a shout, I'll send you the changes via e-mail.
Cheers, Gerry