News:

Looking for documentation? Take a look on our wiki

Main Menu

Removing part of the canonical link

Started by Meton, December 01, 2015, 23:35:49 PM

Previous topic - Next topic

Meton

Hi guys,

I am trying to setup a nice looking canonical URL for my manufacturer products.

What i am trying to do is the following.

I want to create a menu that points to a single manufacturer and show all the products directly. I am doing that currently by showing the following menu:

Menu Title = Brand X

Menu Item Type * = Catagory Layout
Select a Category * = Top Level Catagory
Select a Manufacturer = Brand X

All works fine exept the canonical link is not that good. It shows:

www.shop.nl/brand_X/manufacturer/brand_X

I would like to change this to just
www.shop.nl/brand_X

Setting this up by using category's is not possible because i have overlapping catagories and i want to be able to show a category with all manufacturers. Example:

www.shop.nl/bike

The category bike contains all products of different manufacturers. (this category will be disabled form indexing)

Kind regards,

Meton
Joomla!         3.6.5
VirtueMart     3.0.18

Meton

I found a solution (i think  ::)) but can someone confirm if this is the correct way to do this?

I created a overwrite on category/view.hyml.php and changed the following:

// remove joomla canonical before adding it
foreach ( $document->_links as $k => $array ) {
if ( $array['relation'] == 'canonical' ) {
unset($document->_links[$k]);
break;
}
}

$link = 'index.php?option=com_virtuemart&view=category';
if($categoryId!==-1){
$link .= '&virtuemart_category_id='.$categoryId;
}
if($manId!==-1 && $manId >=1){
$link .= '&virtuemart_manufacturer_id='.$manId;
}

$document->addHeadLink( JRoute::_($link, false, -1) , 'canonical', 'rel', '' );

}



To
// remove joomla canonical before adding it
foreach ( $document->_links as $k => $array ) {
if ( $array['relation'] == 'canonical' ) {
unset($document->_links[$k]);
break;
}
}

$link = 'index.php?option=com_virtuemart&view=category';
if($categoryId!==-1){
$link .= '&virtuemart_category_id='.$categoryId;
}
if($manId!==-1 and !empty($manId)){
$link .= '&virtuemart_category_id='.$categoryId;
}

$document->addHeadLink( JRoute::_($link, FALSE) , 'canonical', 'rel', '' );

}


Kind regards,

Meton
Joomla!         3.6.5
VirtueMart     3.0.18