Spice up your internal sNews CMS search page with result descriptions

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 :)

Search meta descriptions



You might like


Thanks Matt

Yay, finally! Thanks :-)

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.

Simply and nice :D
Good work, again ;)

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

- artAB
- artBA
- artAB
- artCC

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

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 <span class="highlight">c.</span>id DESC LIMIT '.$limit;

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

A goodie one... Thanks.

nice, thank you matt :)

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) ...

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. :)

Damn fine hack, Matt!
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

Once again, another unbelievably easy to install and useful snews mod. Thanks!!

Thanks poultry man! Haven't spent much time with any CMS in a while, but its nice to see people still find these useful.

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top