Add meta keywords to your categories in sNews 1.7

Add meta keywords to your categories in sNews 1.7

This is a simple mod that you can use to add a keywords meta field to your categories. I have implemented it on my own site here for the last several days and it's working well. This is a fairly easy mod, however, make sure to follow the instructions well, don't use a different field name due to conflicts with existing fields, otherwise you'll have to re-write many existing queries.

Category meta keywords

To begin, we need to add the field to your categories table.

ALTER TABLE categories ADD keywords_m VARCHAR(255) AFTER description;

Now, as always, back-up your snews.php and work off of a copy.

Around line 172, add the keywords_m field to the selection.

$R = mysql_fetch_assoc($Try_Article);
// query  for / category / article /
if(empty($R)) {
    $MainQuery = 'SELECT
   AS catID, AS name, c.description, c.subcat,
   AS xname,c.keywords_m as keywords_m
        FROM '._PRE.'categories'.' AS x

Around line 198, add the keywords_m field to the selection.

$R = mysql_fetch_assoc($Try_Page);
if (!$R) {
    $MainQuery ='SELECT
            id AS catID, name, description, keywords_m
        FROM '._PRE.'categories'.' AS c

Around line 232, add the keywords_m elseif condition.

if(!empty($R['keywords_meta'])) $_KEYW = $R['keywords_meta']; elseif(!empty($R['keywords_m'])) $_KEYW = $R['keywords_m'];

Around line 1748, within function from_categories, add the highlighted code.

$query = mysql_query('SELECT id,name,seftitle,published,keywords_m,description,subcat,catorder FROM '._PRE.'categories'.' WHERE id='.$categoryid);

Around line 1763, within function form_categories, add the highlighted line.

$frm_description = $r['description'];
$frm_keywords = $r['keywords_m'];
$frm_publish = $r['published'] == 'YES' ? 'ok' : '';

Around line 1789, within function form_categories, add the highlighted line.

echo html_input('text', 'description', 'desc', $frm_description, l('description'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'keywords_m', 'keywords_m', $frm_keywords, l('a_keywords'), '', '', '', '', '', '', '', '', '', '');
if (empty($sub_cat)) {
    echo '<p>'.l('subcategory').': <br />'; category_list($categoryid); echo '</p>';

Around line 2568, within function processing, add the highlighted line.

$keywords_meta = entity($_POST['keywords_meta']);
$keywords_m = entity($_POST['keywords_m']);
$display_title = $_POST['display_title'] == 'on' ? 'YES' : 'NO';

Around line 2768, within function processing, add the highlighted code to the add and edit processes.

    $catorder = mysql_fetch_array(mysql_query(
        "SELECT MAX(catorder) as max
        FROM "._PRE.'categories'." WHERE subcat = $subcat"));
    $catorder = $catorder['max'] + 1;
    mysql_query("INSERT INTO "._PRE.'categories'."
        (name, seftitle, description, keywords_m, published, catorder, subcat)
        VALUES('$name', '$seftitle', '$description', '$keywords_m', '$publish_category', '$catorder','$subcat')");
    $catorder = mysql_fetch_array(mysql_query(
        "SELECT MAX(catorder) as max
        FROM "._PRE.'categories'." WHERE subcat = $subcat"));
    $catorder = isset($_POST['catorder']) ? $_POST['catorder'] : $catorder['max'] + 1;
    mysql_query("UPDATE "._PRE.'categories'." SET
        name = '$name',
        seftitle = '$seftitle',
        description = '$description',
        keywords_m = '$keywords_m',
        published = '$publish_category',
        WHERE id = $id LIMIT 1");

That should do it, upload your snews.php and now you should be able to add meta keywords to your categories. These keywords will be displayed once you've added them, until then, it will use the site default. As always, if something is screwy, let me know and I'll have a look.



You might like


Oumpf! Took me 5 minutes. Where's the karma button?
Oh yes! On the forum. See you there.

Excellent. Thanks a million Matt :)

Thank you very much for your contribution about snews, you are a nice guy !
karma button is to click on his Ads :)

Thanks Thom, Tina, & Sven!

You're right Thom. Except I don't see any ads.

Hmmm, are you using adblock extension maybe? Or perhaps the ads aren't relevant, in which case I have Google not serve anything and fold the space up.

No matter anyways, I wouldn't encourage clicking for the sake of clicking, Google is pretty smart in that regard.

Sometimes I think about removing adsense altogether, most months it pays for hosting, but that's about it. I think most folks are ad-blind these days :)

"I wouldn't encourage clicking for the sake of clicking, Google is pretty smart in that regard."
I know you are fair Matt.

I just went on another page about gaming and saw and ad. So it works. You gonna be a millionaire soon. ;-)

Is it necessary for what purposes?

It's not "necessary" really, Different, it's just another way to fine-tune SEO.

The default sNews will show the generic site settings keywords on categories, this allows you to have category specific keywords.

Hi Matt...
and sub-categories?
Do you think it worth it?


I believe the above does work with sub-categories? Unless I forgot to document a step or something.

Does it?
Here no. Nothing is stored in the DB on my side.

Hmmm, something is odd then, because a sub-category is simply a category below another, everything else is the same.

You're saying that the sub-category keywords don't get inserted into the DB, but a regular category's keywords do?

I think I got a bug somewhere locally in the DB...
waitee waitee...
I got some issues to fix and I'll be back tomorrow.

I just remember I had an issue there. ;-)

Hi Matt
I gave another try this morning: keywords are stored into the DB. That's good news.
There are printed too into the meta keywords. But I don't use this meta which is deprecated by search engines. I thought I would find them into the meta tags, bout no: even in the administration panel I can't see them printed.
Thats' my bug in fact.

Hii Mad, how I can make urls in plain text and replace < with true tag in comment and article post, please teach me, thanks

Hi Abdul,

There exists a small line within the comment function to convert the commenter's website url to a link, use can just use that convert plain text links within the comment text.

I'm not really sure what you mean about true tags?

information is very helpful...!
how its application on blogspot..?


Hi ghee, I would have no idea how to implement on blogspot, I've never used it.

I think blogspot is a hosted application anyways, so it's probably a featured the developers themselves would have to add.

I have sNews on my site and anxious to try try this.. many things havent worked for my language; hope this one does :)

Thanks mdj for the mod.
Just a small fix when you edit a category existing keywords are not displayed.

function form_categories

$query = mysql_query('SELECT id,name,seftitle,published,description,keywords_m,subcat, catorder FROM '._PRE.'categories'.' WHERE id='.$categoryid);

Hi Danny!

Hmmm, it works on mine, I believe the two edits in the function form_categories at lines 1763 & 1789 should do that?

We just added the keywords_m to the existing categories query and populate the field with that.

Can you double check you made those two edits correctly?

Hi Matt !

You're right, this is in the administration panel, if you want to edit the existing keywords of category.

Whoops, I left out the step where you add the keywords_m selection to the exiting query... you don't need a separate query as you're already selecting the cat information from the database.

I have added the step to the article, the part at line 1748.

Thanks for catching that & letting me know Danny.

Comments are closed. No new comments allowed.

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