Spice up your internal sNews CMS search page with result descriptions
Jun 3rd, 2009 at 9:28 am
filed under: sNews CMS / Hacks & Mods
filed under: sNews CMS / Hacks & Mods
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 :)
10 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Redbeard (I managed to get Vampire: The Masquerade - Bloodlines ...)
- Tina (Installed this today and working like a charm :) Thanks!)
- Tina (Thanks for this great mod :) Working on my site for quite a ...)
- konga (Hi Matt, if you plan to update it, please have a look into ...)
- David (Yo Matt, I have a problem, when I use this mod. ...)
- Dave (Have a Toshiba NB305. Win7 starter would not do screen ...)
- Daichisan (Howdy Matt, I dont really get it, whats ...)
- Matt (Mine is just customized further, that's all :) It just spits ...)
- Matt (David, Do you own or admin the server? Do you have exec ...)
Popular Entries
- Compact archives for sNews 1.7 (5/5)
- Light-weight related articles mod for sNews 1.7 (4.78/5)
- SEF / SEO search for your sNews website (4.75/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.67/5)
- Gravatar mod for sNews 1.7 (4.67/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
- Related Articles mod for sNews CMS, public beta release (4.6/5)
- An easy mod to create custom break titles for your sNews articles (4.6/5)
Jun 3rd, 2009 at 5:15 pm
Thanks Matt
PP
Jun 4th, 2009 at 1:06 pm
Yay, finally! Thanks :-)
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.
Jun 11th, 2009 at 2:47 am
Excellent! Bravo!
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.
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
and change it to
$query = $query.' ORDER BY c.id DESC LIMIT '.$limit;that will order by the category ids, not the article ids.
Jan 25th, 2010 at 9:34 am
A goodie one... Thanks.
Apr 7th, 2010 at 6:22 pm
nice, thank you matt :)
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) ...
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. :)