Jump to content

[SOLVED] top horizontal menu , create submenu links


Recommended Posts

hello,

  

  i need to create a new menu category on the ,'top horizontal menu' ,for my website, for example:

  

(parent category)   THE COMPANY

  (1st child)                          About us

  (2nd child)                         Partners

 (3rd child)                           Gallery

 

this seems that it cannot be done from the configuration of the module (in the administration area).

 

 

is there a way to create these links as i show above?

 

my third child is a link of a gallery module, so can i put the link on a CMS page ?

 

thank you.

Edited by vekia (see edit history)
  • Like 1
Link to comment
Share on other sites

hello

 

you can create:

cms category: The Company

cms pages: About us, Parners, Gallery

 

then  in top horizontal menu add The Company category, it will appear as a separate item with dropdown list with pages attached to this category

  • Like 6
Link to comment
Share on other sites

hello Vekia, you are always here to help, i can count on you.

 

so, ok for the 'the company' and 'partners' i can create them as cms page.

 

 what about the 'photos', it is just a link to the gallery module , like : index.php?fc=module&module=azgallery&controller=gallery 

 

Can i write something inside the 'Page content' and redirect me to the image gallery ?

Link to comment
Share on other sites

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

  • Like 5
Link to comment
Share on other sites

hello Vekia, i got it.

  

when you say id == 4 you actually mean the id of the gallery cms (i will create a cms which i will name it gallery.) and on the URL_TO_GALLERY i am going to write the link to load the gallery. 

it is a clever trick, i will try it and i will let you know asap.

 

thnks.

Link to comment
Share on other sites

  • 3 weeks later...

hello,


i need to add a link in the top horizontal menu.


In my menu there are all my products categories and they show the related subcategories.


Now in the list of subcategories of the category 2 i would like to add a link to a cms page.


 


is there a way to create this link?


thanks


Link to comment
Share on other sites

 

hello,

i need to add a link in the top horizontal menu.

In my menu there are all my products categories and they show the related subcategories.

Now in the list of subcategories of the category 2 i would like to add a link to a cms page.

 

is there a way to create this link?

thanks

 

 

what you mean by category 2 ? it's a category ID, or what?

Link to comment
Share on other sites

Hi vekia,

 

please what do you mean exactly when you say: "then in top horizontal menu add The Company category" ? How do you achieve that? 

 

I've been trying this way:

- created category

- created pages in that category

- saved

 

but nothing appears in my top menu (using default theme on prestashop 1.5.6.1)

 

Thx

Link to comment
Share on other sites

Hi Paulito,

 

and thank you for you reply.

 

Yes, I'm trying to have items on the top horizontal menu. For the moment I only have there a Home tag, I wish I could add something like The Company with subcategories, as per the image you linked. I still can't find out how to do that! Any help would be appreciated.

Link to comment
Share on other sites

Good morning

 

Using PS 1.5.5 default theme

 

This is showing you how to add CMS pages to the default Horizontal menu. You can, of course add many links by repeating #6

 

OK try this:

 

1. http://screencast.com/t/geziRlxn

 

2. http://screencast.com/t/Pkj7wQwv

 

3. http://screencast.com/t/nfPhUj5PR

 

4. http://screencast.com/t/pepOxY0t

 

5. http://screencast.com/t/XZh4q7lmqRm

 

6. Go to: Back office > Modules > Modules > Front office features > scroll down to Top horizontal menu > Configure

    http://screencast.com/t/a9qFcoxEY

 

7. Result

    http://screencast.com/t/MNKhCnLzMm

 

Hope this helps

 

Paul

 

PS. Don't forget to use the same language

  • Like 1
Link to comment
Share on other sites

hello albigin,

Paulito gave you a complete and in detail solution about how to create the CmsMenu, i hope it is clear to you now.

 

As for the second part of your question , 'how to add a link to a gallery under that menu':

 

let me ask you something, can you code? are you familiar with the presta architecure?

because only with custom code can it be done, there is no ready configuration for that.

 

1st.     You add another one 'child cms page' and call it Gallery, under your cms menu.

2nd.    You open the php file that controls the top menu, blocktopmenu.php

3rd.     You should do the Vekia's proposal, and you will have a link that redirects to a gallery:

 

If i were you i will create CMS page then in blocktopmenu.php file instead of:

            foreach ($pages as $page)
            {
                $cms = new CMS($page['id_cms'], (int)$id_lang);
                $links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

                $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                $this->_menu .= '<li '.$selected.'>';
                $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
                $this->_menu .= '</li>';
            }

use this:

    foreach ($pages as $page)
            {
                $cms = new CMS($page['id_cms'], (int)$id_lang);
                $links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

                $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
if ($cms->id==4){
                $this->_menu .= '<li '.$selected.'>';
                $this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
                $this->_menu .= '</li>';
} else {
$this->_menu .= '<li '.$selected.'>';
                $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
                $this->_menu .= '</li>';
}
            }

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

 

  4th  kindly take a look on my conversation with Vekia in order to copmletely understand the solution.

 

 

Link to comment
Share on other sites

Just to add - Paul's instructions are perfect for CMS pages, but if you want to click on the dropdown entry to go to something other than a CMS page (e.g. the photo gallery in the original post), you'll need to use the code change provided by Vekia in post #4.

Cheers, Dave

 

Hey tornado, great minds think alike!

Edited by stottycabanas (see edit history)
Link to comment
Share on other sites

dear Paul, stottycabanas and tornado1979

 

sorry for the delay in replying to you kind posts: I was celebrating my stepmother's birthday (I live in Italy and presently it is 16:12 hours).

 

What Paul sent me is very, very clear: I was missing step #6. I followed the instrucions and now the top menu works like a charm. 

 

Thank you very, very much for sharing your knowledge with the community, I hope I could help you as kindly as you did with me
Link to comment
Share on other sites

  • 2 weeks later...

Hi I have achieved to add cms categories with subpages/subcategories to the top horizontal menu. 
But I wan't to add productcategories(not cms categories) as submenu to a cms page or just having the productcategories being gathered under different menuitems from home as it is now. How can I achieve that? see below images:

One image shows what I wan't and the other shows that currently categories are only bound to home.

 

post-734931-0-09446300-1387133742_thumb.png

post-734931-0-18613400-1387133757_thumb.png

Link to comment
Share on other sites

  • 1 month later...

 

 

Horizontal menu advanced

you mean default menu? or some external solution?

 

 

 

in the admin ?

i think that there is no module for create menu in back office, because to create menu items in BO, you have to create controllers to handle these menu items.

Link to comment
Share on other sites

  • 1 month later...

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

 

Hello Vekia,

 

Thanks for your solution, really works.

 

How can I add more than one CMS links?  I had got add one link with your solution, but when I copy the code twice and insert other ID and link, I get a menú with categories CMS duplicate. Also I tested with other changes and happens the same.

 

Do you can Help me please?

Edited by Maelux (see edit history)
Link to comment
Share on other sites

you can add additional if conditions in elseif clause, take a look:

if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } elseif ($cms->id==7) {
                    $this->_menu .= '<li '.$selected.'>';
                    $this->_menu .= '<a href="URL_TO_ANOTHER_PAGE>'.$cms->meta_title.'</a>';
                    $this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
Link to comment
Share on other sites

 

you can add additional if conditions in elseif clause, take a look:

if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } elseif ($cms->id==7) {
                    $this->_menu .= '<li '.$selected.'>';
                    $this->_menu .= '<a href="URL_TO_ANOTHER_PAGE>'.$cms->meta_title.'</a>';
                    $this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }

 

Thank you very much Vekia, works perfectly¡

Edited by Maelux (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Hello, please guys,

 

How can I change the time top menu takes to show subcategories when pass mouse over?

In Prestashop 1.6, top menu is very slow showing up on hover. I would like it open immediate, no delay.

I'd tried find in CSS but nothing found. The only one I'd found is delay time for it desapear. But I want reduct delay for OPEN.

 

Thanks in advance!

Link to comment
Share on other sites

It's SOLVED. Changed the speed of Top Menu!!!! So it opens immediately on mouse hover. Just edit the file:

 

/Themes/Default-bootstrap/js/modules/blocktopmenu/js/hoverIntent.js

 

Put "interval": 0

 

 // default configuration values
        var cfg = {
            interval: 000,
            sensitivity: 7,
            timeout: 0
     };
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for sharing! its work fine!

 

Can I remove the default link when click on the CMS on the top menu because I dont want to display the list of that CMS. Also, if the list displayed the "Gallery" method on the list will not working and only display a blank Gallery page!

 

Thank for advice!!

Link to comment
Share on other sites

  • 1 month later...

May I reopen this topic?

 

I'm working on Persta 1.6, and would like to make an itemon the top menu with 3 sub items on it. Such sub items are external links.

 

I've created the 3 external links on the module back office, but I don't know how to tie them in a submenu.

 

thanks everybody,

Link to comment
Share on other sites

  • 3 weeks later...

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

 

 

Thx Vekia for this nice little change. Its working perfect. 

 

 

This solution is also working for mulitshops, right?

Edited by wakabayashi (see edit history)
Link to comment
Share on other sites

  • 2 months later...

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

 

I tried and it did not work. Should we do something more?

Thanksss!!!

Link to comment
Share on other sites

  • 3 months later...

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

This seems like a great workaround, but it's not working for me: default-bootstrap, 1.6.

 

I'm trying to add "manufacturers pages" as submenu links to a CMS page.

 

For example:

 

/index.php?id_cms=4&controller=cms

 ----/index.php?id_manufacturer=20&controller=manufacturer  

-----/index.php?id_manufacturer=21&controller=manufacturer

-----/index.php?id_manufacturer=22&controller=manufacturer

 

Thanks V, you're the only reason I can do Prestashop!

 

GT

Link to comment
Share on other sites

  • 1 month later...

Another solution (if you don't want add an hardcoded ID in your code) is :

 

 if (strpos($cms->meta_description, 'REDIRECT:') !== False) {
    $this->_menu .= '<a href="'.str_replace("REDIRECT:", "", $cms->meta_description).'">'.$cms->meta_title.'</a>';
}
else {
    $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
}

That allow you  to set: "REDIRECT:/myblog" in meta description of a cms page...

 

So in your menu, you can add this cms page, which one will be just a link to a external page...

 

You can see here an example : https://www.perfecthealthsolutions.eu in the "Informations +" Menu

 

PS : I do it in meta_description, but you can do it in your favorite field.

But perso, I prefere to keep the $cms->content() with a simple link to allow a fallback if I update the module and forget to cherry pick this change !

 

 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
I tried to do this but it is something wrong.

I created the category and the pages cms and changed the code but does not work in the topmenu.

When checking the link it appears only in the child page and weirder is that the link is there even after I delete the code in menutop

what is happening here???

Link to comment
Share on other sites

 

I tried to do this but it is something wrong.
I created the category and the pages cms and changed the code but does not work in the topmenu.
When checking the link it appears only in the child page and weirder is that the link is there even after I delete the code in menutop
what is happening here???

 

 

Ok, I need to update de topmenu after code changings :D

I dont no why but only the yrejk code work for me

Link to comment
Share on other sites

  • 4 weeks later...

 

Another solution (if you don't want add an hardcoded ID in your code) is :

 

 if (strpos($cms->meta_description, 'REDIRECT:') !== False) {
    $this->_menu .= '<a href="'.str_replace("REDIRECT:", "", $cms->meta_description).'">'.$cms->meta_title.'</a>';
}
else {
    $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
}

That allow you  to set: "REDIRECT:/myblog" in meta description of a cms page...

 

So in your menu, you can add this cms page, which one will be just a link to a external page...

 

You can see here an example : https://www.perfecthealthsolutions.eu in the "Informations +" Menu

 

PS : I do it in meta_description, but you can do it in your favorite field.

But perso, I prefere to keep the $cms->content() with a simple link to allow a fallback if I update the module and forget to cherry pick this change !

 

 

 

hi.

Can you explain more of?

In one file, and where do you use it?

REDIRECT and link, rather than what to do?

Should they instead use vekia code?

Thank you.

Link to comment
Share on other sites

  • 4 weeks later...

hi.

Can you explain more of?

In one file, and where do you use it?

REDIRECT and link, rather than what to do?

Should they instead use vekia code?

Thank you.

 

You need change file:

modules/blocktopmenu/blocktopmenu.php

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				
				if (strpos($cms->meta_description, 'REDIRECT:') !== False) {
					$this->_menu .= '<li '.$selected.'>';
				    $this->_menu .= '<a href="'.str_replace("REDIRECT:", "", $cms->meta_description).'">'.$cms->meta_title.'</a>';
				   	$this->_menu .= '</li>';
				}
				else {
					$this->_menu .= '<li '.$selected.'>';
					$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
					$this->_menu .= '</li>';
				}
			}
Don't forget, if you need deactivate top category item link of CMS menu to list of CMS articles, you need change too this section (only remove code inside href):

				case 'CMS_CAT':
					$category = new CMSCategory((int)$id, (int)$id_lang);
					if (count($category))
					{
						$this->_menu .= '<li><a href="" title="'.$category->name.'">'.$category->name.'</a>';
						$this->getCMSMenuItems($category->id);
						$this->_menu .= '</li>'.PHP_EOL;
					}
					break;
Edited by igi008 (see edit history)
Link to comment
Share on other sites

Hi, I tried vekia's code but instead my whole website just went blank.

May I know the url what kind of format that I need to use?

 

 

I tried 'www.website.com/contact-us'

and '/contact-us' 

 

both are not working

 

is it because my cms is under another cms page? so it's actually a sub menu of a cms page.

 

Help!

Link to comment
Share on other sites

Hi, I tried vekia's code but instead my whole website just went blank.

May I know the url what kind of format that I need to use?

 

 

I tried 'www.website.com/contact-us'

and '/contact-us' 

 

both are not working

 

is it because my cms is under another cms page? so it's actually a sub menu of a cms page.

 

Help!

I think, both of them are correct (I preffer second way most). But your problem could be with new version of module  (actual is 2.2.0 - updated 2 days ago - I had problems after update, I am using older version yet)

 

You can try version 2.1.0 and way described in my post above (updated yrejk's post). In my case works good.

Edited by igi008 (see edit history)
Link to comment
Share on other sites

  • 4 months later...

I put here my own solution to generate custom threes on the top menu with custom links.

 

In blocktopmenu.php replace the for located in line 659 by this for.

foreach ($categories as $category) {
                $cat = new CMSCategory((int)$category['id_cms_category'], (int)$id_lang);
				$cat_link = "";
				if($cat->description === 'link')
				{
					$cat_link = $cat->link_rewrite;
				}
				else
				{
					$cat_link = Tools::HtmlEntitiesUTF8($cat->getLink());
				}
                $this->_menu .= '<li>';
                $this->_menu .= $cat->description.'<a href="'.$cat_link.'">'.$category['name'].'</a>';
                $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1);
                $this->_menu .= '</li>';
            }

I use CMS category to build the threes. I decide to use the field "description" to notify that is special link filling "link" value. In this case, you can create a CMS category called "My link", with "link" in descripcion and your link in friendly-url caption. 

 

When the description field is "link", the code use the friendly-url. You can put here any link, thus categories links.

if($cat->description === 'link')
{
$cat_link = $cat->link_rewrite;
}
Edited by templaries (see edit history)
Link to comment
Share on other sites

  • 2 months later...

 

You need change file:

modules/blocktopmenu/blocktopmenu.php

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				
				if (strpos($cms->meta_description, 'REDIRECT:') !== False) {
					$this->_menu .= '<li '.$selected.'>';
				    $this->_menu .= '<a href="'.str_replace("REDIRECT:", "", $cms->meta_description).'">'.$cms->meta_title.'</a>';
				   	$this->_menu .= '</li>';
				}
				else {
					$this->_menu .= '<li '.$selected.'>';
					$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
					$this->_menu .= '</li>';
				}
			}
Don't forget, if you need deactivate top category item link of CMS menu to list of CMS articles, you need change too this section (only remove code inside href):

				case 'CMS_CAT':
					$category = new CMSCategory((int)$id, (int)$id_lang);
					if (count($category))
					{
						$this->_menu .= '<li><a href="" title="'.$category->name.'">'.$category->name.'</a>';
						$this->getCMSMenuItems($category->id);
						$this->_menu .= '</li>'.PHP_EOL;
					}
					break;

I use this solution and is working on 1.6.1.3.

I use this to put tag links in top menu.

Because tag menu have invalid carachters (+, =, ?)  I  use this tutorial to extend tinyMCE and disable auto-paragraph adding : https://mypresta.eu/en/art/prestashop-16/extended-rich-text-editor.html  and I use $content  to put my link.

My code is:

				if (strpos($cms->content, 'REDIRECT:') !== False) {
					$this->_menu .= '<li '.$selected.'>';
				    $this->_menu .= '<a href="'.str_replace("REDIRECT:", "", $cms->content).'">'.$cms->meta_title.'</a>';
				   	$this->_menu .= '</li>';
				}

The blank page problem is most likely  because of closing tags after "else" zone

				}
			}
Link to comment
Share on other sites

  • 1 month later...

Hi all guys, I'm trying to do the same with different languages.

 

I need to do some thing like:

 

if ($cms->id==13){
$this->_menu .= '<li '.$selected.'>';
 
                    if SELECTED LANGUAGE BY USER IN FRONT OFFICE IS ITALIAN <- how to write this??? {  link in Italian below
                    $this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_raccordi_tubo_flessibile.pdf" target="_blank">'.$cms->meta_title.'</a>';
                     }
                     else if SELECTED LANGUAGE BY USER IN FRONT OFFICE IS ENGLISH <- how to write this??? {  link in English below
                    $this->_menu .= '<a href="http://newsite.rimaoil.it/listini/flexible_hose_pricelist.pdf" target="_blank">'.$cms->meta_title.'</a>';
 
$this->_menu .= '</li>';
                }
 
...
 
else {
                $this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';    
                }
 
 

Anyone can help?

 

Thank you very much guys

Edited by silvioscavone (see edit history)
Link to comment
Share on other sites

  • 11 months later...
I was edit this code in modules/blocktopmenu/blocktopmenu.php to change links of subcategories but it does not working. what should i do?

 

 


foreach ($categories as $category)
{
$cat = new CMSCategory((int)$category['id_cms_category'], (int)$id_lang);


                if ($cat->id==27){
$this->_menu .= '<li>';
                $this->_menu .= '<a href="http://timelife.vn/12-san-pham#/gioi_tinh-nam">'.$category['name'].'</a>';
                $this->_menu .= '</li>';
                } 
                elseif ($cat->id==28){
$this->_menu .= '<li>';
                $this->_menu .= '<a href="http://timelife.vn/12-san-pham#/gioi_tinh-nu">'.$category['name'].'</a>';
                $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1);
                $this->_menu .= '</li>';
                }
                else {
                $this->_menu .= '<li>';
                $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($cat->getLink()).'">'.$category['name'].'</a>';
                $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1);
                $this->_menu .= '</li>';    
                }
}
Link to comment
Share on other sites

  • 5 months later...

If i were you i will create CMS page then in blocktopmenu.php file instead of:

			foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
			}

use this:

	foreach ($pages as $page)
			{
				$cms = new CMS($page['id_cms'], (int)$id_lang);
				$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

				$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                if ($cms->id==4){
				$this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';
                } else {
                $this->_menu .= '<li '.$selected.'>';
				$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
				$this->_menu .= '</li>';    
                }
			}

if ($cms->id==4)  - this is if condition with ID of gallery cms page. instead of "URL_TO_GALLERY" use url to your gallery page

 

Hi, I know it's a old post, but the thread is the same of my question:

is it possible to adapt this solution also to products category?

I mean if is it possible, in the top horizontal menu, to add a custom link in the subcategory window.

Link to comment
Share on other sites

  • 1 month later...

Hello,

 

Trying to search the same solution to place a external link on a cms id page like vekia explaned, but i need this for prestashop 1.7.2 in the ps_mainmenu.php file.

 

where and how (same code for 1.7 ?) can i place this solution ?

 

if ($cms->id==4){
                $this->_menu .= '<li '.$selected.'>';
                $this->_menu .= '<a href="URL_TO_GALLERY">'.$cms->meta_title.'</a>';
                $this->_menu .= '</li>';
} else {

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

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