Jump to content

[SOLVED] Displaying different HTML code depending of the PARENT category i'm in


Recommended Posts

I have been searching the forum up and down but i couldn't get any solution working..

I'm trying to display different HTML code in "header.tpl" depending of the parent category i'm in, this should work for both subcategories pages and product pages..

Ideally i need something along this lines:

{if $category == 37}HTML info 1
{elseif $category == 45}HTML info 2
{else}default HTML info{/if} 



where $category is the Parent ID of the subcategory/product page i'm currently browsing.

Can this be done? Many many thanks in advance.

Link to comment
Share on other sites

Unfortunately, there is no parent category variable available in PrestaShop, so your only option is to modify PrestaShop to add it. Edit header.php and add the following code before the $smarty->display:

if (isset($_GET['id_category']) AND $_GET['id_category'] > 0)
{
  $category = new Category($_GET['id_category']);

  if (Validate::isLoadedObject($category))
     $smarty->assign('id_parent', $category->id_parent);
}



You can then use the following code in header.tpl:

{if $id_parent == 45}
Your code here
{/if}

Link to comment
Share on other sites

Thanks very much for the help rocky, your method seems to detect PARENT minus 1 level though.

I'm having the following structure:

Home > Parent category (id=44) > Subcategory (id=45) > Subcategory1 (id=45) > PRODUCT

This works:

{if $id_parent == 45}
text here
{/if}



Hower this:

{if $id_parent == 44}
text here
{/if}


doesn't work.

Any ideas how can i detect a level up?

Next time i'm having balance in my PayPal account i'm going to donate at the "donate" link in your site for all the help you provide over here, you should put a "donate" link in your sig though, you deseve it!

Link to comment
Share on other sites

Ignore my last post, i didn't get it the first time :)

But i'm having a big issue,
the IF statements work while browsing categories but don't work while looking at a product page, just noticed this and it's a big problem .. any clue ? Help please !

it seems like i need to also get the Parent_ID of the product?

Link to comment
Share on other sites

You are correct. You'll need to check the id_product too. Try the following code:

if (isset($_GET['id_category']) AND $_GET['id_category'] > 0)
  $category = new Category($_GET['id_category']);
elseif (isset($_GET['id_product']) AND $_GET['id_product'] > 0)
{
  $product = new Product($_GET['id_product']);
  $category = new Category($product->id_category_default);
}

if (isset($category) AND Validate::isLoadedObject($category))
  $smarty->assign('id_parent', $category->id_parent);



There already is a Donate link on the menu at the top of my site. Is it not obvious enough?

Link to comment
Share on other sites

  • 5 months later...

Hello!
Rocky i have a doubt!
I'm doing a website that in header.tpl it's included one Div that contains Flash.swf file!
I'd like to know if is it possible to load multiple *.tpl files depending on the Category ID.

I've been searching on this forum and i found mutiples post's that teach how to load multiples header's.jpg and backgrounds.

The function that i found here is:



Are there a way to say something like this:

<{_PS_BASE_DIR}={$theme_dir}header{if $category == xxx OR $category == xxx}{$category}{/if}.tpl>

???

Wating an answer!

Regards from Portugal!

Mano

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...