efr Posted October 21, 2011 Share Posted October 21, 2011 Hi, I'm having some problems to get category ID in header.tpl while in product page. Here is the code i put in header.php (inspired from http://www.prestasho...name-in-header/ , thanks to his author) class FrontController extends FrontControllerCore { public function displayHeader() { $pathinfo = pathinfo(__FILE__); $page_name = basename($_SERVER['PHP_SELF'], '.'.$pathinfo['extension']); $page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name; if ($page_name == 'product' AND isset($_GET['id_product'])) $product = new Product($_GET['id_product'], false, intval(self::$cookie->id_lang)); if (Validate::isLoadedObject($product)) self::$smarty->assign('id_category_default', $product->id_category_default); } parent::displayHeader(); } } and the code in header.tpl {if isset($id_category_default)}{$id_category_default}{else}{l s='Something else'}{/if} Anybody has an idea why it doesn't work ? My prestashop version is 1.4.4.1 Thank you very much efr Link to comment Share on other sites More sharing options...
efr Posted October 24, 2011 Author Share Posted October 24, 2011 Solved ! My fault, i made a mistake placing the code given by rocky in header.php, and not in classes/FrontController.php thank you for reading, and thanks to rocky for its code ! Link to comment Share on other sites More sharing options...
Consultor SEO - jlmora Posted December 3, 2012 Share Posted December 3, 2012 (edited) Hi, I'm having some problems to get category ID in header.tpl while in product page. Here is the code i put header.php (inspired from http://www.prestasho...name-in-header/ , thanks to his author) class FrontController extends FrontControllerCore { public function displayHeader() { $pathinfo = pathinfo(__FILE__); $page_name = basename($_SERVER['PHP_SELF'], '.'.$pathinfo['extension']); $page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name; if ($page_name == 'product' AND isset($_GET['id_product'])) $product = new Product($_GET['id_product'], false, intval(self::$cookie->id_lang)); if (Validate::isLoadedObject($product)) self::$smarty->assign('id_category_default', $product->id_category_default); } parent::displayHeader(); } } and the code in header.tpl {if isset($id_category_default)}{$id_category_default}{else}{l s='Something else'}{/if} Anybody has an idea why it doesn't work ? My prestashop version is 1.4.4.1 Thank you very much efr Hi, i want to show canonical link in header in header.tpl <!-- canonical --> {if $page_name == 'index' or $page_name == 'search'} <link rel="canonical" href="{$base_dir}" /> {elseif $page_name == 'category' or $page_name == 'best-sales' or $page_name == 'cart' or $page_name == 'discount' or $page_name == 'manufacturer' or $page_name == 'new-products' or $page_name == 'prices-drop'} <link rel="canonical" href="{$base_dir}{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {else} <link rel="canonical" href="{$base_dir}{$product->id_category_default}{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {/if} But {$product->id_category_default} is not accesible from header.tpl Edited December 3, 2012 by jlmora (see edit history) Link to comment Share on other sites More sharing options...
Consultor SEO - jlmora Posted December 3, 2012 Share Posted December 3, 2012 Hi, i want to show canonical link in header in header.tpl <!-- canonical --> {if $page_name == 'index' or $page_name == 'search'} <link rel="canonical" href="{$base_dir}" /> {elseif $page_name == 'category' or $page_name == 'best-sales' or $page_name == 'cart' or $page_name == 'discount' or $page_name == 'manufacturer' or $page_name == 'new-products' or $page_name == 'prices-drop'} <link rel="canonical" href="{$base_dir}{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {else} <link rel="canonical" href="{$base_dir}{$product->id_category_default}{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {/if} But {$product->id_category_default} is not accesible from header.tpl Link to comment Share on other sites More sharing options...
pedes Posted April 8, 2016 Share Posted April 8, 2016 Hello, I need to have the category id also in the header, I would like to change the header logo if the customer visit 1 specific category. Or is there another way to do this? Please can you explain where to put what code. I'm using Prestashop 1.6.1.4 Thank you very much Kind regards Peter Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now