Jump to content

product-list.tpl template change depending on category


ctdesign87

Recommended Posts

hi there

i have managed to sucessfully change the product-list-tpl depending on which category is selected.

however i have an issue related to efficiency.

within the product-list.tpl file i've inserted the following code:

{if $category->id == 75 || $category->id == 76 || $category->id == 77 || $category->id == 78 || $category->id == 79 || $category->id == 80 || $category->id == 81 || $category->id == 82 || $category->id == 83 || $category->id == 84 || $category->id == 85 || $category->id == 86 || $category->id == 87 || $category->id == 88 || $category->id == 89 || $category->id == 90 || $category->id == 91 || $category->id == 92 || $category->id == 93 || $category->id == 94 || $category->id == 95 || $category->id == 96 || $category->id == 97 || $category->id == 98 || $category->id == 99}



surely there would be a more efficient way for the server going through this list of numbers and having to see if it matches to satisfy the conditions of the if statement.

can anyone suggest a step by step process to making this more efficient? im looking into arrays atm, but am getting confused atm.

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...
hi there

 

i have managed to sucessfully change the product-list-tpl depending on which category is selected.

 

however i have an issue related to efficiency.

 

within the product-list.tpl file i've inserted the following code:

{if $category->id == 75 || $category->id == 76 || $category->id == 77 || $category->id == 78 || $category->id == 79 || $category->id == 80 || $category->id == 81 || $category->id == 82 || $category->id == 83 || $category->id == 84 || $category->id == 85 || $category->id == 86 || $category->id == 87 || $category->id == 88 || $category->id == 89 || $category->id == 90 || $category->id == 91 || $category->id == 92 || $category->id == 93 || $category->id == 94 || $category->id == 95 || $category->id == 96 || $category->id == 97 || $category->id == 98 || $category->id == 99}

 

surely there would be a more efficient way for the server going through this list of numbers and having to see if it matches to satisfy the conditions of the if statement.

 

can anyone suggest a step by step process to making this more efficient? im looking into arrays atm, but am getting confused atm.

 

Can I just say a huge thank you, this as helped me out tremendously! Thanks

Link to comment
Share on other sites

  • 2 months later...

Hi!

 

I know it's a litte bit old, but I would use 'in_array' function.

First define an array containning all th ID's You want.

Then check if the '$categoty->$id' is in that array.

Below is an example:

{$id_array = [78,79,...,90,91]}
{if in_array($category->$id, $id_array)}
do something
{/if}

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