Jump to content

[SOLVED] Adding categories as exception to show a block module? (or how to display a module block only in one category...?)


Elcon_D
 Share

Recommended Posts

Hi,

Firstly thanks for the solutions and modules to the good people that work for the community, it has been very useful to read these threads since I started to work with Prestashop.

Today I encourage myself to write and ask you because I have a problem that is driving me crazy, changing code here and there..

I want to show a module block only in one category and keep it hidden in the rest. The first thing I tried was easy, I went to "positions" in "modules" and I added "category.php" as exception . Obviously the block disappeared in all categories. After that I tried adding "category.php" with modifiers, (for example, "category.php? Id_category = 24") ... but id didn't work, the block displays normally this way.

I've seen some thread where somebody was asking for something similar ( add as exception in the module individual pages of CMS (eg: instead of putting the exception "cms.php" put "cms.php? Id_cms = 2"), but no solution was encountered.

The question is:

Does anybody know, or comes up with a way for a block module to appear in some categories and keep hidden in on others?

I tend to think that some lines of code can solve this, but my programming skills are quite limited...

Thank you very much in advance! :)

Share this post


Link to post
Share on other sites

You could add the following to the top of a block's tpl file:

{if $smarty.get.id_category == 2}



and the following to the bottom:

{/if}



This will make the block only display on the category 2 page.

Share this post


Link to post
Share on other sites

You could add the following to the top of a block's tpl file:

{if $smarty.get.id_category == 2}



and the following to the bottom:

{/if}



This will make the block only display on the category 2 page.



So easy! :lol: Thank you Rocky !!!

Share this post


Link to post
Share on other sites

  • 4 weeks later...
  • 8 months later...

Hi guys, i have a questions in a similar area......how would i go about displaying the categories block on all category pages, except the main one? IE all pages except category.php?id_category=1

The exception function only seems to allow you to put a page, IE category.php as an option

Any help is massively appreciated!

Share this post


Link to post
Share on other sites

It's not possible to do that using exceptions. You must modify code. For example, edit modules/blockcategories/blockcategories.tpl and add the following to the top:

{if $smarty.get.id_category != 1}



and the following at the bottom:

{/if}

  • Like 1

Share this post


Link to post
Share on other sites

Great! that worked for the categories bloc. Thank you.

Im trying to do this with the newletter v1.4 as well... IE so it doesnt appear on the category 1 page ....it doesnt seem to have a tpl file though? Any experience with this module?

Share this post


Link to post
Share on other sites

  • 3 months later...

Edit modules/productscategory/productscategory.php and change lines 53-54 from:

if (!$category->active) 
   return;



to:

if (!$category->active OR $category->id == 2) 
   return;



Change 2 to the ID of the category you don't want the "In the same category" section to appear on.

Share this post


Link to post
Share on other sites

Thank you rocky for posting this! Works like a charm. But to concerns: As I want the blockcart not shown on homepage and all cms-pages, I was trying this:

{if $smarty.get.id_cms != 7 OR $smarty.get.id_category != 8}


This is producing an error in lines, which aren't affected? When I reduce my coding to

{if $smarty.get.id_cms != 7}


it works. Any Ideas?
And - how should I adress the homepage, wch isn't a cms nor a category?

Thanks for helping,
jens

Share this post


Link to post
Share on other sites

Maybe, I should think a little longer ...

I've got it working this way:
Let's say, the lowest number of my categories is 3, then my code is

{if $smarty.get.id_category > 3}

So now, as the cms-pages are not categories as well as the homepage the blockcart appears only on productpages;)

jens

  • Like 1

Share this post


Link to post
Share on other sites

  • 5 months later...

is it possible to display Categories block in all products related to one category? I am able to display only in one category but also wanted to display it in the products that are tagged to that category.

Please help me on this

Share this post


Link to post
Share on other sites

  • 1 year later...

Hi Rocky,

 

This works like charm...

 

But i have a problem, i have more than 350 categories this code "

{if $smarty.get.id_category == 2 OR $smarty.get.id_category == 3 OR $smarty.get.id_category == 4}

"

is not workign for many categories more than 25.

 

What exactly i need is i want to show category blocks for categories between Id no's 135 and 235.

 

How to acheive it ?

Share this post


Link to post
Share on other sites

  • 7 months later...
  • 5 months later...

[solved]

 

Hello.

 

I need blocknewproducts no show in index.

 

I probe in tpl files insert:

 

{if $page_name != 'index' AND $page_name != 'cms'}    

....

....(original content)

....

{/if}

 

but don't work. it is showed in "start" page always.

 

How to remove it from start page. Please.

 

SOLUTION: prestashop 1.6 have hooks for home page.

 

thanks

Edited by mokadik (see edit history)

Share this post


Link to post
Share on other sites

modules > positions search for module on each available list there, click on edit button and define exception for that module, you can select "index" (homepage) and module will not appear there anymore 

  • Like 1

Share this post


Link to post
Share on other sites

modules > positions search for module on each available list there, click on edit button and define exception for that module, you can select "index" (homepage) and module will not appear there anymore 

Yes that is. I was modify the post with solution.

 

Thanks. Thanks.

Share this post


Link to post
Share on other sites

  • 5 months later...

Hi Rocky,

 

This works like charm...

 

But i have a problem, i have more than 350 categories this code "

{if $smarty.get.id_category == 2 OR $smarty.get.id_category == 3 OR $smarty.get.id_category == 4}

"

is not workign for many categories more than 25.

 

What exactly i need is i want to show category blocks for categories between Id no's 135 and 235.

 

How to acheive it ?

Hi, vivek.sakhilati did you solve your problem? If so, would you mind sharing how please? Thanks

Share this post


Link to post
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More