Jump to content

[solved] Name of the category to meta title?


2grosiek7

Recommended Posts

you have to change Meta class, go to the classes\Meta.php and look for function:

 

public static function getProductMetas($id_product, $id_lang, $page_name)
{
...
}

 

You need use script for getting category name:

$sql = 'SELECT id_category_default FROM `'._DB_PREFIX_.'product` WHERE id_product = '.(int)$id_product.'';
$row_cat = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
$cat=new Category($row_cat['id_category_default'],(int)$id_lang);
$row['meta_title']=$row['meta_title']." ".$cat->name;

 

paste it into getProductMetas() function, to the if condition:

 

if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{

------- HERE -------

if (empty($row['meta_description']))
  $row['meta_description'] = strip_tags($row['description_short']);
return Meta::completeMetaTags($row, $row['name']);
}

 

final modified function:

 

public static function getProductMetas($id_product, $id_lang, $page_name)
{
 $sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
'.Shop::addSqlAssociation('product', 'p').'
WHERE pl.id_lang = '.(int)$id_lang.'
 AND pl.id_product = '.(int)$id_product.'
 AND product_shop.active = 1';
 if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
 {

	  $sql = 'SELECT id_category_default FROM `'._DB_PREFIX_.'product` WHERE id_product = '.(int)$id_product.'';
	  $row_cat = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
	  $cat=new Category($row_cat['id_category_default'],(int)$id_lang);
	  $row['meta_title']=$row['meta_title']." ".$cat->name;


  if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['description_short']);
  return Meta::completeMetaTags($row, $row['name']);
 }
 return Meta::getHomeMetas($id_lang, $page_name);
}

 

 

the most important thing in code above is a part below:

 

$row['meta_title']=$row['meta_title']." ".$cat->name;

 

$row['name'] - product name

$cat->name - category name

 

your tittle will looks like:

 

"Macbook Laptops"

  • Like 2
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

you have to change Meta class, go to the classes\Meta.php and look for function:

 

(...)

 

the most important thing in code above is a part below:

 

$row['meta_title']=$row['meta_title']." ".$cat->name;

 

$row['name'] - product name

$cat->name - category name

 

your tittle will looks like:

 

"Macbook Laptops"

 

Hi Vekia. I found an issue with this code. If i add anything to $row['meta_title'] variable, my meta title is empty.

 

$row['meta_title']=$row['meta_title']." ".$cat->name;

This code display only category name.

 

Anyone know where is problem?

 

Oh, i'm using prestashop 1.5.4

 

Thanks.

Edited by rytek (see edit history)
Link to comment
Share on other sites

Ok, but, if i keep original file, my title is like: $productName - $shopName.

If i try to add something to $row['meta_title'], title will be empty.

$row['meta_title'] .= "test";

result: test

 

But, if i assign:

$row['meta_title'] = $row['meta_title']; - title will be normally displayed.

$row['meta_title']=$row['meta_title']." ".$cat->name; - only category name will be displayed.

Edited by rytek (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

Hey guys, I am trying to get this fixed and I can not figure it out. I attached the seo problems it keeps telling me. My website is www.ppiultrasound.com. One is my H1 tag can not be found and also my logo i believe is not  <img> tag does not have an ALT attribute defined.   Any help would be great. Thank you!

 

 

post-750617-0-17226500-1390071988_thumb.png

Link to comment
Share on other sites

hello

 

and how it's related to meta title, which is a main case in this topic?

if you've got questions not related to this thread - please create new one.

it will be much more visible then, and this will be helpful for whole community too :)

 

thanks in afvane

Link to comment
Share on other sites

Hello Vekia, thank you for your work.

I have a problem with this, i was modify meta.php like in this article and when i reload site....white, i upload original meta.php, but same problem. moto-anvelope.ro What i need to do now, because i dont know. Thank you again.

Codrin

 

white page means that you probably changed something wrong :)

Link to comment
Share on other sites

sure, i can help

 

turn on error reporting, this is the most important step in debug process

and let me know what you see after that

 

open config/defines.inc.php

 
find this line: define('_PS_MODE_DEV_', false);
change to look like this: define('_PS_MODE_DEV_', true);

 

with regards,

Milos

Link to comment
Share on other sites

sure, i can help

 

turn on error reporting, this is the most important step in debug process

and let me know what you see after that

 

open config/defines.inc.php

 
find this line: define('_PS_MODE_DEV_', false);
change to look like this: define('_PS_MODE_DEV_', true);

 

with regards,

Milos

Huhh, i will, put below the errors, thank you.

 

Warning: Function getDefaultCountryId() is deprecated in /home/rser1893/public_html/moto-anvelope.ro/modules/homecarousel/homecarousel.php on line 278

in /home/rser1893/public_html/moto-anvelope.ro/classes/Tools.php on line 2137

 

Notice: Undefined variable: category in /home/rser1893/public_html/moto-anvelope.ro/modules/homecarousel/homecarousel.php on line 340

 

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file '/home/rser1893/public_html/moto-anvelope.ro/themes/default/./header.tpl' in '/home/rser1893/public_html/moto-anvelope.ro/themes/default/layout.tpl'' in /home/rser1893/public_html/moto-anvelope.ro/tools/smarty/sysplugins/smarty_internal_templatebase.php:127 Stack trace: #0 /home/rser1893/public_html/moto-anvelope.ro/tools/smarty/sysplugins/smarty_internal_template.php(286): Smarty_Internal_TemplateBase->fetch(NULL, NULL, NULL, NULL, false, false, true) #1 /home/rser1893/public_html/moto-anvelope.ro/cache/smarty/compile/76/f0/ef/76f0ef7e1fef534e5bd56f59c49b64ee1b075f22.file.layout.tpl.php(31): Smarty_Internal_Template->getSubTemplate('/home/rser1893/...', NULL, NULL, NULL, NULL, Array, 0) #2 /home/rser1893/public_html/moto-anvelope.ro/tools/smarty/sysplugins/smarty_internal_templatebase.php(180): content_52dc0adaac24d1_99242479(Object(Smarty_Internal_Template)) #3 /home/rser1893/public_html/moto-anvelope.ro/tools/smarty/sysplugins/ in /home/rser1893/public_html/moto-anvelope.ro/tools/smarty/sysplugins/smarty_internal_templatebase.php on line 127

Link to comment
Share on other sites

ok, so let me explain:

 

 

Warning: Function getDefaultCountryId() is deprecated in /home/rser1893/public_html/moto-

it's not an error, it's a prestashop internal message that homecarousel use deprecated functions. it doesn't affect website, it's just short information about that. nothing more. the same with notice message about undefined varialbe in homecarousel.

 

problem is with fatal error.

does the header.tpl file exist in your theme directory?

Link to comment
Share on other sites

ok, so let me explain:

it's not an error, it's a prestashop internal message that homecarousel use deprecated functions. it doesn't affect website, it's just short information about that. nothing more. the same with notice message about undefined varialbe in homecarousel.

 

problem is with fatal error.

does the header.tpl file exist in your theme directory?

    Vekia, thank you verry verry much for your work, i see the problem finaly, i have missing my header.tpl and product.tpl from directory, i resolved this, Question is why?, i used HTML Block from presta.eu , and made some modification at the template with this block, but today when i looked for this block in BO, surprise, it is no longer. I am only one who have acces in BO and CPanel. You have any ideea, or another that this problem? Thank you again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...