Jump to content

Solved / Solucionado: Add an external link to a subcategory


Anca Amalia

Recommended Posts

Hi,

 

I need to add a link to a subcategory of one of the category of the mail menu. I mean I have the category Publicity Items and as subcategories of it Vehicles Items, Religious Commemorations, ...., Others Items and I need to add an external link to this last subcategory. I´ve tried changing the code from module/blockcategories/category-tree-branch.tpl with 

 

 
 
 
 
 
<a href={if $node.id == 218} http://www.google.es {else}{$node.link|escape:html:'UTF-8'}{/if}  {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}
    title="{$node.desc|strip_tags|trim|truncate:255:'...'|escape:'html':'UTF-8'}">{$node.name|escape:'html':'UTF-8'}</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
but nothing happens...
 
 
 
 
Thanks.
 
Edited by Anca Amalia (see edit history)
Link to comment
Share on other sites

Hi Anca,

 

The file is normally overridden in the theme dependent folder, so try to edit it here:

 

themes/<your theme folder>/modules/blockcategories/category-tree-branch.tpl

 

At least you should see some action :-)

 

 

(Also, temporarily set force compilation to YES and smarty cache = OFF in advanced parameters->Performance, otherwise the old/cached version keeps showing. Don't forget to put these option back to the old values after you see it's working, otherwise your site will be slooooow)

 

My 2 cents,

pascal

Link to comment
Share on other sites

Hi Pascal,

 

Thanks for the replay. That`s the file I've changed and I've changed the other one too just in case, but,no, it is not working...Nothing happens.....

 

I also forced complilation, smarty chache off, no cache and also delete history... and nothing :(

 

Any idea?

Link to comment
Share on other sites

Hmm, can  you add some nonsense text in front of the name, just to see if the file compiles?

 

 

<a href={if $node.id == 218} http://www.google.es {else}{$node.link|escape:html:'UTF-8'}{/if}  {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}
    title="{$node.desc|strip_tags|trim|truncate:255:'...'|escape:'html':'UTF-8'}">AAAAAA{$node.name|escape:'html':'UTF-8'}</a>
Link to comment
Share on other sites

To add a fixed link to the top menu, you can go to the configure screen of the top horizontal menu and then at the bottom "add a new link"

 

The path you can just find by going to the page you want to link to and copy the URL. Past this in the link field.

 

Hope that's what you needed. If not, please elaborate.

 

pascal.

Link to comment
Share on other sites

Hi Pascal,

 

I now you can add the link to a category from the top horizontal menu. my inquiery is how you add the link to a subcategory of one of the category of the top horizontal menu.

 

I mean, for example you have as a category of the top horizontal menu Publicity Items and one of it subcategory is More Items. Well with the code modification made, the link is applied to this subcategory More Items in the Vertical Menu, but no link is applied in the top horizontal menu.

 

Thanks again for your colaboration...

Link to comment
Share on other sites

Ah, sorry,

 

So you have a special sub category in the top horizontal menu, (For diana, category with 218) but want to have the link changed into a fixed external link right?   (See image)

post-455771-0-57432200-1430292405_thumb.png

 

 

 

 

Let me have a look at that.

 

Patience...

 

pascal.

Link to comment
Share on other sites

OK,

 

 

Edit file:   (make backup!!!)

  modules/blocktopmenu/blocktopmenu.php

 

in function:

  private function generateCategoriesMenu($categories, $is_children = 0)
 

 

add red code:

 

private function generateCategoriesMenu($categories, $is_children = 0)
{
  $html = '';
 
  foreach ($categories as $key => $category)
  {
    if ($category['level_depth'] > 1)
    {
      $cat = new Category($category['id_category']);
      if ((int)$cat->id_category == 5)  // change 5 to your category id
        $link = "http://google.com/";   // change to your own URL
      else 
        $link = Tools::HtmlEntitiesUTF8($cat->getLink());
  }
  else
    $link = $this->context->link->getPageLink('index');
 

 

 

Then, make sure in advanced parameters ->Performance

Your force compilation is ON, and smarty Cache is OFF (and press "clear cache" in top right of this page)

 

Then load any page with top menu, and see if it works.

post-455771-0-17029200-1430302474_thumb.png

 

 

Hope this is what you needed,

 

pascal

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

Cant find this (private function generateCategoriesMenu($categories, $is_children = 0)in my files. 

I want to add a subcategory link that links to a manufacturer page on my site.

CATEGORIES

   Fine Watches

             *Rolex (I want these 2 subcategories to be links to my manufacturer page with the corresponding products) 

               *Panerai

 

Please Help

Thanks Johnny

                          

Link to comment
Share on other sites

  • 3 months later...

Hello Pascal,
 
i've done exactly like u've explained above with no success. I replaced categories number with several and no luck.
 
my blocktopmenu.php looks like this:

 

 protected function generateCategoriesMenu($categories, $is_children = 0)
    {
        $html = '';
 
        foreach ($categories as $key => $category) {
            if ($category['level_depth'] > 1) {
                $cat = new Category($category['id_category']);
                if ((int)$cat->id_category == 2)  
$link = "anpc.gov.ro";   // change to your own URL 
$link = Tools::HtmlEntitiesUTF8($cat->getLink());
            } else {
                $link = $this->context->link->getPageLink('index');
            }
 
I'm rather new to Prestashop, and don't have that much PhP experience...
 
What i want to do is this:
Have a menu: Terms and conditions with several items: (legal advice, refund policy, etc). Some of the "items" will be direct external links to state authorities, so i can't go to another CMS page and from there to the external URL. Is it even possible?
 
Thank you in advance, 
Edited by bogdanpatr (see edit history)
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...