1

I'm trying to get a div to show on a specific Magento webpage and hide on others. Specifically on the top Category level.

If someone can show me a code to do this which can be based off the Category ID or the website's URL, it would be perfect.

Within the div will be a basic button navigation which will take the user to another page.

The current code is currently in the 2columns-left.phtml, and as you can see there are buttons called: Wheels - Hubs - Rims - Spokes - Nipple Sets - Brake Discs.

This would be fine if all the categories had this option but they do not, so I need to make specific buttons for each top level category: Motocross-Enduro, Supermoto, Speedway, Road, Classic and Clearance.

http://smprowheels.ortigaprototypes.co.uk/motocross-enduro.html

So if anyone can help me in finding out a way to hide divs based on the magento category or url I'd appreciate it.

2
  • So did any of the answers help you get the job done?
    – Badger
    Oct 9, 2015 at 13:10
  • Milan's response regarding the extension was the one I went for :)
    – A. Lal
    Oct 11, 2015 at 21:24

2 Answers 2

0

Why not use this free extension to show the subcategories list?

http://www.magentocommerce.com/magento-connect/subcategories-grid-list.html

(I'm not affiliated with this extension in any way, but have used it for clients in the past and it works great)

Using the extension you wouldn't have to manually create these blocks per category. The extension also offers an option to exclude specific category ids.

1
  • Thanks for your input, that extension has helped a lot, I am working with this now, currently customising the CSS a bit.
    – A. Lal
    Oct 11, 2015 at 21:23
0

Guess you have several ways to do this. In my opinion building a simple module would do the trick. You can then design a template file that you would assign to the preferred location on your page. You can then build in the logic that would either hide or show the button based on the category ID.

Getting the current category ID would look something like this:

$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();

You can use an array for example to insert the Id's of the categories that need the button to be shown (or the other way around). A simple foreach could check if the Id of the current category is present in the array and if so show the button, or not...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.