• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Add canonical links to your site [SEO]
PostPosted: Wed Oct 06, 2010 3:09 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Thu May 14, 2009 8:11 pm
Posts: 1264
Location: Lithuania
Idea is to tell googol link to a page with only required url params. More info http://googlewebmastercentral.blogspot. ... nical.html

I created UDT that strips off extra params in url. Than it can be used as canonical url. This UDT is created for Products detail view but can easily be adopted to any other module. It uses "ugly" url and $config['process_whole_template'] = false;.
Quote:
/**
* Get product details canonical url
*
* @params string $params['url_param_list'] Comma separated list of parameters to be kept in new url. Default  'mact,cntnt01productid,hl'
* @params string $params['url'] URL to be modified. Default $config['root_url'].$_SERVER['REQUEST_URI'];
* @params string $params['assign'] Assign value to.
*
*/

//prepare parameter
if(empty($params['url_param_list'])){
$url_param_list = 'mact,cntnt01productid,hl';
}
else{
$url_param_list = trim($params['url_param_list']);
}
if(empty($params['url'])){
$config = cmsms()->GetConfig(); // cms_utils :: get_config();
$url = $config['root_url'].$_SERVER['REQUEST_URI'];
}
else{
$url_param_list = trim($params['url']);
}
$return = array();

//modify url query
$query_string = parse_url($url, PHP_URL_QUERY);
$url_params_to_save = explode(',', $url_param_list);
parse_str($query_string, $data);
foreach($data as $key => $url_param){
if(!in_array($key, $url_params_to_save)){
unset($data[$key]);
}
}
$url_query = http_build_query($data, '', '&');

//recreate url
$return = str_replace($query_string, $url_query, $url);

//assign to smarty if needed
if(!empty($params['assign'])){
$smarty = cmsms()->GetSmarty(); // cms_utils :: get_smarty();
$assign = trim($params['assign']);
$smarty->assign($assign, $return);
}
else{
return($return);
}


Call it in Products detail template
Quote:
{get_canonical_url assign='canonical_url' url_param_list='mact,cntnt01productid,hl'}


Add canonical link to meta data ("Site Admin » Global Settings > Global Settings > Global Metadata:")
Quote:
{if !empty($canonical_url)}

{/if}

_________________
My best friends are: FAQ: How can I debug my code/site ?...showtemplate=false...module_customhow to create a patch, {process_pagedata}
And Yours ? :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Add canonical links to your site [SEO]
PostPosted: Wed Dec 15, 2010 2:47 pm 
Offline
Forum Members
Forum Members

Joined: Wed Jul 15, 2009 12:35 am
Posts: 110
I noticed no one hasn't replied yet. I was reading the link you sent earlier, and didn't know my site was using a 'www' and 'http://'.

Thanks, will look deeper into it.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting