Hi David
I want to add a Meta Description to /category/ pages
Example: {link saved}
Note I have sent you my tapestry.php file as we are removing the /category/ from the URL but still would like a Meta Description for what is still a category page
Can this be added to the admin area?
Thanks
Stuart
Hi David I have created dbmod.php
Added this to {link saved}
Or should be under "Scripts"?
I also downloaded admin/categories.php but couldn't find the following code
$sql = "UPDATE `".$config_databaseTablePrefix."categories` SET alternates = '".database_safe(widget_posted($alternates))."' WHERE id='".database_safe($id)."'";
or
print " ";
Maybe we had previous mods!
Regards
Stuart
Hi Stuart,
That's the right place for dbmod.php - run from there and it should display "Done.".
My apologies - the code mods refer to admin/categories_configure.php which is where you should find the code...!
Cheers,
David.
--
PriceTapestry.com
Thanks David
It is not displaying "Done" - any ideas?
I'll make the changes to the other admin/categories_configure.php
Stuart
Hi Stuart,
I just ran it through on my test server successfully - continue with the mods and double check that you can save the meta description field; either way, I'll forward the dbmod.php that I just used by email for you to use if not...
Cheers,
David.
--
PriceTapestry.com
Hi David,
I used this method to add my own on category pages (I used meta_title in place of meta_description). Everything is ok until the search.php step. This is what I tried :
if ($parts[0]=="category")
{
$sql2 = "SELECT meta_description,meta_title FROM `".$config_databaseTablePrefix."categories` WHERE name='".database_safe($parts[1])."'";
if (database_querySelect($sql2,$rows2))
{
$header["meta"]["description"] =
htmlentities($rows2[0]["meta_description"],ENT_QUOTES,$config_charset);
$header["meta"]["title"] =
htmlentities($rows2[0]["meta_title"],ENT_QUOTES,$config_charset);
}
}
Unfortunately, it gives 2 metas in the source
- The original , displaying the category name
- and a another meta : (No interest for SEO)
How can I replace the original TITLE in category pages with my own variable ?
Thanks David !
Bak
Hi Bak,
As long as the mod appears after the default $header["title"] is set (around line 320):
$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
...then you can overwrite it in your mod as follows:
if ($parts[0]=="category")
{
$sql2 = "SELECT meta_description,meta_title FROM `".$config_databaseTablePrefix."categories` WHERE name='".database_safe($parts[1])."'";
if (database_querySelect($sql2,$rows2))
{
$header["meta"]["description"] =
htmlentities($rows2[0]["meta_description"],ENT_QUOTES,$config_charset);
$header["meta"]["title"] =
htmlentities($rows2[0]["meta_title"],ENT_QUOTES,$config_charset);
$header["title"] =
htmlentities($rows2[0]["meta_title"],ENT_QUOTES,$config_charset);
}
}
Cheers,
David.
--
PriceTapestry.com
Hi Stuart,
Sure - firstly, to add a custom field to the Category Mapping interface, first add a new field `meta_description` to the `categories` table with the following dbmod.php script.
<?php
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."categories`
ADD `meta_description` TEXT NOT NULL";
database_queryModify($sql,$result);
print "Done.";
?>
Next, edit admin/categories.php and look for the following code at line 64:
$sql = "UPDATE `".$config_databaseTablePrefix."categories` SET alternates = '".database_safe(widget_posted($alternates))."' WHERE id='".database_safe($id)."'";
...and REPLACE with:
$sql = "UPDATE `".$config_databaseTablePrefix."categories` SET alternates = '".database_safe(widget_posted($alternates))."',meta_description='".database_safe(widget_posted($_POST["meta_description"]))."' WHERE id='".database_safe($id)."'";
Then look for the following code at line 94:
print "<input type='submit' name='submit' value='Save' /> ";
...and REPLACE with:
print "Meta Description:<br />";
print "<textarea style='width:100%;' name='meta_description' rows='5' cols='50'>".widget_safe($category["meta_description"])."</textarea>";
print "<br /><br />";
print "<input type='submit' name='submit' value='Save' /> ";
Finally to use the new field on category pages, look for the following code at line 320 of search.php
$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
...and REPLACE with:
if ($parts[0]=="category")
{
$sql2 = "SELECT meta_description FROM `".$config_databaseTablePrefix."categories` WHERE name='".database_safe($parts[1])."'";
if (database_querySelect($sql2,$rows2))
{
$header["meta"]["description"] =
htmlentities($rows2[0]["meta_description"],ENT_QUOTES,$config_charset);
}
}
$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
Note that you don't actually need to use the actual mapping feature of Category Mapping - you can just create a new Category Mapping for any category for which you want to enter a custom meta description and leave the Alternatives box empty on the configuration page for the mapping...
Cheers,
David.
--
PriceTapestry.com