Jump to content

Block Categories - show only current category


Recommended Posts

Hi Guys,

 

i use julien breux horizontal navigation menu. I search a synchronized version of the block categories modul. My need is the following: If I select a category via the horizontal menu, only the selected category and it's subcategories should appear in the categories block in the left hook.

 

Does anyone know a modul with this functionality or could give me some hints were I need to modify the modul?

 

Merry Christmas to everyone and I appreciate any help. Thanks.

 

Chris

Link to comment
Share on other sites

Hi Snade,

 

thanks for you reply. I already have a horizontal top menu.

I've attached a screenshot of my actual test template. I want to change the left categories block. If I select the category 'iPods' in the horizontal top menu, only iPods and it's 2 subcategories should appear in the left category list.

 

Do you know how to change it?

 

thanks and kind regards

Chris

post-271208-0-87800900-1324855860_thumb.png

Link to comment
Share on other sites

So, I came up with a solution but I cant get it fully working.

The idea is to have display:none; on all <li> elements in the menu, and change that to display:block, for the selected category.

 

It sounds easy, and it is if you dont have subcategories.

 

So first I added display:none to the #categories_block_left li

and display:block to #categories_block_left li ul li (when you have selected a main category, the subcategories need to show up)

 

then I edited category-tree-branch like that


<li {if isset($last) && $last == 'true'}class="last" {/if}{if isset($currentCategoryId) && ($node.id == $currentCategoryId)}style="display:block"{/if}>

which just add style="display:block" to the <li> when this is the current category.

 

works fine for the main categories.

 

But when you select a subcategory, the parent category <li> no longer get display:block (which is perfectly normal when you think about it.... )

 

Somehow we have to link the currentcategoryid to the parent_id or something...

 

 

Maybe someone else can give a clue how this can be achieved ?

 

 

@herchri Change the name of the topic to "Block Categories - show only current category" or something like that. Probably it will drive more attention than just block categories

Link to comment
Share on other sites

Do I understand the modul correctly?

 

blockcategories.tpl delivers the main categories and category-tree-branch.tpl delivers the subcategories and highlights the active category ?

 

Now I tried to add an 'if' condition in block categories.tpl , but I think I'm still on the wrong way ... I tried to add the following:

 

    {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
    {foreach from=$blockCategTree.children item=child name=blockCategTree}
	    {if $smarty.foreach.blockCategTree.last}
		    {include file="$branche_tpl_path" node=$child  last='true'}
	    {else}
		    {include file="$branche_tpl_path" node=$child}

	    {/if}
    {/foreach}
    {/if}

Link to comment
Share on other sites

Both main categories and subcategories are generated in category-tree-branch. That is the problem, we need to make an if statement not only for current category, but for current category and its parent categories.

 

 

Here is an idea, but I want you to try it since I dont have time.

 

{if isset($id_category_parent) && ($node.id == $id_category_parent)}style="display:block"{/if}

(this will not be the final code, just test it to see if its working for parent category)

Link to comment
Share on other sites

Ok, looks much better now. Great. Now I've only one issue. I want, that the label of the left categories box - at the moment 'Kategorien' - gets automatically exchanged by the highest parent category - in my example 'iPods' -

 

Does anyone have an idea for this?

post-271208-0-21927700-1324910517_thumb.png

Link to comment
Share on other sites

  • 2 weeks later...

That's how I solved it, using Snade's idea + javascript call to parent tags:

 

1) in category-tree-branch.tpl i wrote

<li class="{if isset($last) && $last == 'true'}last {/if} menulist" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}id="currentli"{/if}>

2) add new javascript function in tools.js (it could be any .js file, called on your page)

function  changevisibility()
{
document.getElementById('currentli').parentNode.parentNode.id = "parid";
}

3) add in <body> tage on header.tpl:

onload="changevisibility()"

 

So this function will be called when our page is just loaded

4) add in global.css

#categories_block_left li {display:none;}
li#parid, li#parid #currentli,  li#parid ul, li#parid ul li, #currentli, #currentli ul li{display: block !important;}

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
Guest masquemortal

well thank you both for sharing that solution!, maybe will test it later on my shop, it could be usefull, thanks again

Link to comment
Share on other sites

Guest masquemortal

last chuvachon solution for changing the name of categorie block title, didnt work for me.

 

The other one solution for showing only parent categorie in block, works fine on 1.4.6.2

Link to comment
Share on other sites

  • 11 months later...

So I wouldn't say I solved this because it doesn't work for all cases.

But I use this modified version of the blockcategories module.

 

Since on my webpage the categories block is only displayed on category pages, this works good, but I know that it doesn't work properly on product pages.

 

In order to solve this you should modify the getTree method on blockcategories_mod.php, assigning the initial category id (the one that conveniences you) to $id_category.

 

I hope this is useful for somebody!

blockcategories_mod.zip

Link to comment
Share on other sites

  • 2 months later...

I want to display the home categories for all pages in the left sidebar. It works fine.

 

Then, For one of the category page I need to display the current category in the left sidebar.

 

How can I do? How can I enable current category for one of the category page I have  an  idea. I have to change the home category to a current category for that particular category.

 

But I don't know how to achieve using code?

 

Can anyone help, please..

Link to comment
Share on other sites

×
×
  • Create New...