Nuclear Bulldog Posted May 14, 2009 Share Posted May 14, 2009 Hi all,What i want to do is create a variable banner (different one per category).Does someone know if there is a way to get the current category id in the header.tpl. So i can use that to retrieve the picture that i can select when i create a category.Greetz,Jaro Link to comment Share on other sites More sharing options...
Hardik Posted November 2, 2009 Share Posted November 2, 2009 this feature would be really nice... looking forward to someone posting here about this topic. Link to comment Share on other sites More sharing options...
rocky Posted November 2, 2009 Share Posted November 2, 2009 Edit header.php and change: $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken(), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'content_only' => intval(Tools::getValue('content_only')) )); to: $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken(), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'content_only' => intval(Tools::getValue('content_only')), 'id_category' => $_GET['id_category'] )); Then you can access $id_category in header.tpl. Link to comment Share on other sites More sharing options...
Hardik Posted November 2, 2009 Share Posted November 2, 2009 thanks a gazillionnnn buddy :) can you tell me where i can read about the $_GET function? just for my knowledge.... what does it do?thanks a gazillion once again Link to comment Share on other sites More sharing options...
rocky Posted November 2, 2009 Share Posted November 2, 2009 $_GET contains all the variables that are in the current URL after the question mark. For example, if you went to page.html?var1=1&var2=2 you would have $_GET['var1'] = 1 and $_GET['var2'] = 2. Link to comment Share on other sites More sharing options...
Hardik Posted November 6, 2009 Share Posted November 6, 2009 Hey that code works brilliantly... thank a mil..just needed to know one more thing... the point is that the banner that i want changes per parent category and not for the sub categories... so when a person is browsing the sub categories the banner of the parent category should show.now the issue here is that i can hard code the thing to work with the present categories. but in the future if i add sub categories or parent categories it would be an issue.any hints on this one? Link to comment Share on other sites More sharing options...
steviger Posted November 6, 2009 Share Posted November 6, 2009 @RockyI understand the header.php part but what exactly do I do with: "Then you can access $id_category in header.tpl" ?I have several categories and they all have the same header except for two categories (e.g. ID's)If I understand it correctly I have to put some extra code for the ID's 7 and 8 (in my case) in the header.tpl. But to be honest, I don't know how....Best regards,Steven Link to comment Share on other sites More sharing options...
rocky Posted November 6, 2009 Share Posted November 6, 2009 After entering my code above in header.php, just enter {$id_category} in the header.tpl where you want the current category. Link to comment Share on other sites More sharing options...
Hardik Posted November 7, 2009 Share Posted November 7, 2009 in your header.tpl you can write the following code where you want to show youur banner{if $id_category == 21 }{else}{/if}hope this helps Link to comment Share on other sites More sharing options...
Hardik Posted November 7, 2009 Share Posted November 7, 2009 Hey rocky,Any ideas on my question on how to change the banner for only parent categories without hardcoding the values?Thanks Link to comment Share on other sites More sharing options...
rocky Posted November 7, 2009 Share Posted November 7, 2009 I think you could write something like this in header.php to get the parent category of the current category: $category = new Category($_GET['id_category']); $parentCategory = $category->id_parent; and then pass it in to header.tpl like in my original post. Link to comment Share on other sites More sharing options...
steviger Posted November 9, 2009 Share Posted November 9, 2009 Hi Guys,It works like a charm. Thanks a lot!Cheers,Steven Link to comment Share on other sites More sharing options...
Hardik Posted November 10, 2009 Share Posted November 10, 2009 no problemo buddy, rocky is the one to be thanked Link to comment Share on other sites More sharing options...
Hardik Posted November 18, 2009 Share Posted November 18, 2009 hi,is there a way to use GET() method to get the filename like category.php or contact.php ?let me know.thanks Link to comment Share on other sites More sharing options...
rocky Posted November 18, 2009 Share Posted November 18, 2009 Use $_SERVER['SCRIPT_NAME'] to return '/category.php'. Link to comment Share on other sites More sharing options...
Hardik Posted November 18, 2009 Share Posted November 18, 2009 thanks a mil.the earlier code that you had given me to access the parent category id to change the banner worked great.however i want to use the same in the category-tree-branch.tpl but the $id_parentcategory doesnt seem to be accessible there.is there a way to set it globally or something if not how can one achieve that? Link to comment Share on other sites More sharing options...
rocky Posted November 18, 2009 Share Posted November 18, 2009 You must modify line 10 and 12 of modules/blockcategories/blockcategories.tpl and change them to: {include file=$branche_tpl_path node=$child parent=$parentCategory last='true'} and: {include file=$branche_tpl_path node=$child parent=$parentCategory} This will pass the parent category variable into the template so that you can access it using {$parent}. Link to comment Share on other sites More sharing options...
Hardik Posted November 18, 2009 Share Posted November 18, 2009 doesnt seem to work... is there any $smarty->assign that i need to do in the block-categories.php ??? Link to comment Share on other sites More sharing options...
rocky Posted November 18, 2009 Share Posted November 18, 2009 Yep, like in my previous code, you must enter: $category = new Category($_GET['id_category']); $parentCategory = $category->id_parent; $smarty->assign('parentCategory', $parentCategory); so that $parentCategory can be accessed by blockcategories.tpl and then passed into category-tree-branch.tpl. Link to comment Share on other sites More sharing options...
steviger Posted November 30, 2009 Share Posted November 30, 2009 Hi Guys,I got the code working for the main categories. What I would like to have is that the product page under a main categorie has the the same header. For example:A main categorie has picture 1. When you click on a product in that main categorie it's shows the actual product. In this page I would like to have the same header as it's main categorie(picture 1.) Is that possible and how do I achieve that?Any one?Regards,Steven Link to comment Share on other sites More sharing options...
Hardik Posted November 30, 2009 Share Posted November 30, 2009 Hi steven,I had the same problem. This is how i solved it1) in your header.php you have to do add the code to get the parent category id using the _.Get method as pointed out by rocky earlier in this post2) pass it as a smarty assign for the header.tpl 3) compare the parent id in if statemet in header.tpl for appropriate banner per parent idYou will also have to check for product id by doing a _get(id_product) then use that to get the parent of that product to compare in the header.tpl just in case the user is on the product details page. Link to comment Share on other sites More sharing options...
steviger Posted December 1, 2009 Share Posted December 1, 2009 Hi Hardik,Thanks for your reply. Sorry for being a noob but I not quit get it. What do you mean by "pass it as a smarty assign" and how do I do that?This is my code in the header.php: $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken(), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'content_only' => intval(Tools::getValue('content_only')), 'id_category' => $_GET['id_category'] )); This is the code in the header.tpl: {if $id_category == 2 } {elseif $id_category == 4 } {elseif $id_category == 5 } {elseif $id_category == 7 } {elseif $id_category == 8 } {else} {/if} In this situation every main category has its own header. What do I have to add to make the productpages have the same header as the main category of that product?Thanks a lot in advance.Regards,Steven Link to comment Share on other sites More sharing options...
Hardik Posted December 8, 2009 Share Posted December 8, 2009 Hi Steve,Been a little busy so couldnt reply back. here's the code. I saw your website and noticed that you do not have sub categories, so the below mentioned code should work fine.in your header.php add $category = new Category($_GET['id_category']); $parentCategory = $category->id_parent; if (isset($_GET['id_product'])) { $product = new Product(intval($_GET['id_product'])); $categ1 = $product->id_category_default; } $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken(), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'content_only' => intval(Tools::getValue('content_only')), 'id_parentcategory' => $parentCategory, 'categ1' => $categ1 )); in your header.tpl {if $categ1 == 2 || $id_parentcategory == 2 } {elseif $categ1 == 6 || $id_parentcategory == 6 } {elseif $categ1 == 12 || $id_parentcategory == 12} {elseif $categ1 == 13 || $id_parentcategory == 13} {else} {/if} Hope you can go live as soon as possible. Link to comment Share on other sites More sharing options...
steviger Posted December 8, 2009 Share Posted December 8, 2009 Hi Hardik,That's exactly what I needed. Thanks a lot!Cheers,Steven Link to comment Share on other sites More sharing options...
mahuro Posted July 9, 2010 Share Posted July 9, 2010 Hi guys.I've trying with the $path variable. As you know, this variable is used in breadcrumb to show wherre you are. I´ve been using it to show a different banner for each manufacturer and runs ok, but when I´ve tried to use it with the categorys simply it doesn't work.The file with which I want to work product-list.tpl an this is the code that I´ve using: {assign var='banner' value=$path|lower} {assign var='thecategory' value=$banner} {assign var='width' value='540'} {assign var='height' value='250'} {if ($thecategory == 'category1')} <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}"> <embed src="img/banners/{$thecategory}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed> </object>{/if} {if ($banner == 'manufacturer1')} <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}"> <embed src="img/banners/{$banner}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed> </object> {elseif ($banner == 'manufacturer2')} <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}"> <embed src="img/banners/{$banner}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed> </object> Anyone knows why dosn't work with the categorys if the $path returns category1?Thanks, and sorry for my english (i'm spanish). Link to comment Share on other sites More sharing options...
Recommended Posts