Add meta keywords to your categories in sNews 1.7

Comments (19)

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
            c.id AS catID, c.name AS name, c.description, c.subcat,
            x.name 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 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.

case(isset($_POST['add_category'])):
    $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')");
    break;
case(isset($_POST['edit_category'])):
    $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',
        subcat='$subcat',
        catorder='$catorder'
        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.

bookmark / share this: Bookmark and Share
rated 3.33/5 (6 votes)


19 comments

Add a new comment »

Sven/Philippe Sven/Philippe said:
Mar 27th, 2010 at 5:44 am

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


Tina Tina said:
Mar 30th, 2010 at 4:09 pm

Excellent. Thanks a million Matt :)


Thom Thom said:
Apr 3rd, 2010 at 8:58 pm

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


Matt Matt said:
Apr 5th, 2010 at 7:16 am

Thanks Thom, Tina, & Sven!


Sven/Philippe Sven/Philippe said:
Apr 7th, 2010 at 6:24 am

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


Matt Matt said:
Apr 7th, 2010 at 11:31 am

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


Sven/Philippe Sven/Philippe said:
Apr 7th, 2010 at 12:19 pm

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


Different Different said:
Apr 12th, 2010 at 8:56 am

Is it necessary for what purposes?


Matt Matt said:
Apr 12th, 2010 at 9:00 am

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.


Sven/Philippe Sven/Philippe said:
Apr 22nd, 2010 at 9:48 am

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


Matt Matt said:
Apr 22nd, 2010 at 9:51 am

Sven,

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


Sven/Philippe Sven/Philippe said:
Apr 22nd, 2010 at 10:08 am

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


Matt Matt said:
Apr 22nd, 2010 at 10:27 am

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?


Sven/Philippe Sven/Philippe said:
Apr 22nd, 2010 at 11:44 am

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


Sven/Philippe Sven/Philippe said:
May 15th, 2010 at 4:03 am

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.


Abdul Adhim Abdul Adhim said:
Jul 5th, 2010 at 9:36 pm

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


Matt Matt said:
Jul 19th, 2010 at 8:01 am

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?


ghee ghee said:
Jul 19th, 2010 at 2:57 pm

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

Thanks
Gheevara


Matt Matt (Admin) said:
Jul 19th, 2010 at 3:57 pm

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.



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