Jump to content

[SOLVED] - Display Menu Item Selected


helpmeplease

Recommended Posts

Hi,

I've set up a html menu on my site using the addstuff module. This works fine, but I'd like to be able to mark a page as selected when its been clicked. When I normally build a site I would use a body id tag, for example body id="homepage" and then in the CSS I'd have the page selected using the body id tag in the head content of the html.

Is this possible in Prestashop? - I've looked at the source code on each page but I can't find a way of doing this.

If this isn't possible my second question is, if it's possible to create a menu on the left hand side that includes both category and cms links - and to choose the order and which items are displayed?

Sorry for being greedy with two questions!

Hope someone can help or point me in the right direction - thanks in advance

Best wishes

Brian

Link to comment
Share on other sites

I'm not aware of any module that lets you mix CMS and category links in the left column.

PrestaShop puts the page name as the ID of the page in header.tpl in your theme's directory, so you can use body#new-products for new-products.php, body#contact-form for contact-form.php, etc. If you need to target specific CMS pages, you'll need to modify header.tpl and change line 40 from:

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>



to:

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $page_name == 'cms'} class="cms{$smarty.get.id_cms}"{/if}>



so that you can use body.cms1, body.cms2, etc.

Link to comment
Share on other sites

Hi Rocky,

That worked a treat - Thank You!

I must have spent over 6 hours yesterday trying to work it out for myself with no success

Sorry for the further question - (but I must ask!)

Is there a way of doing this same procedure with the category pages and individual product pages?

I'd like to be able to create a custom menu that highlights options from the cms, category and product pages

If there's not, no worries - and thanks again for your help

Brian

Link to comment
Share on other sites

You could expand on my code to include categories and products like this:

body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $page_name == 'cms'} class="cms{$smarty.get.id_cms}"{elseif $page_name == 'category'} class="category{$smarty.get.id_category}"{elseif $page_name == 'product'} class="product{$smarty.get.id_product}"{/if}>

Link to comment
Share on other sites

  • 2 months later...

This is very good, thanks.

Is there a way that Prestashop can tell the level of subcategories?
ie if it was a sub category of a subcategory?
{elseif $page_name == 'category'}

or if you can give a page name to a specific category?

Link to comment
Share on other sites

  • 2 years later...

in this module blocktopmenu i need the class active i test but not fuction

case 'LNK':
   $selected = ($link->getPageLink == $page_name ) ? ' class="sfHover"' : '';
 $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop);
 if (count($link))
 {
  if (!isset($link[0]['label']) || ($link[0]['label'] == ''))
  {
   $default_language = Configuration::get('PS_LANG_DEFAULT');
   $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID());
  }
  $this->_menu .= '<li'.$selected.' ><a href="'.$link[0]['link'].'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL;
 }
 break;

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