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.
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 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.
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.
Comments
RSS Comments Feed
Sven/Philippe
Oh yes! On the forum. See you there.
Tina
Thom
karma button is to click on his Ads :)
Matt
Sven/Philippe
Matt
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
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
Matt
The default sNews will show the generic site settings keywords on categories, this allows you to have category specific keywords.
Sven/Philippe
and sub-categories?
Do you think it worth it?
Matt
I believe the above does work with sub-categories? Unless I forgot to document a step or something.
Sven/Philippe
Here no. Nothing is stored in the DB on my side.
Matt
You're saying that the sub-category keywords don't get inserted into the DB, but a regular category's keywords do?
Sven/Philippe
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
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
Matt
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
how its application on blogspot..?
Thanks
Gheevara
Matt
I think blogspot is a hosted application anyways, so it's probably a featured the developers themselves would have to add.
tattoos
danny
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);
Matt
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?
danny
You're right, this is in the administration panel, if you want to edit the existing keywords of category.
Matt
I have added the step to the article, the part at line 1748.
Thanks for catching that & letting me know Danny.