Page 1 of 1
					
				[Solved] Canonical link for news articles
				Posted: Sun Sep 13, 2009 12:43 pm
				by Guido
				Hi,
On this forum I found a way to include canonical links in my template. It works, but not for my news articles. I've been looking for a way to make it happen and in my existing news detail template I found:
Code: Select all
{if isset($entry->canonical)}
  {assign var='canonical' value=$entry->canonical}
{/if}
Which looks like a canonical link is automatically assigned for news articles. Doesn't work yet. Is there something I need to add to my {canonical} tag?
 
			
					
				Re: Canonical link for news articles
				Posted: Sun Sep 13, 2009 12:49 pm
				by RonnyK
				Did you set the process_whole_template to false in the config.php?
{* set a canonical variable that can be used in the head section if process_whole_template is false in the config.php *}
Ronny
 
			
					
				Re: Canonical link for news articles
				Posted: Sun Sep 13, 2009 2:55 pm
				by Guido
				proces_whole_template isn't even in my config.php. Could I just add it?
			 
			
					
				Re: Canonical link for news articles
				Posted: Sun Sep 13, 2009 3:01 pm
				by Guido
				proces_whole_template isn't even in my config.php. Could I just add it?
Woops, yes it is. And it's set to false.
 
			
					
				Re: Canonical link for news articles
				Posted: Sun Sep 13, 2009 3:22 pm
				by Guido
				I've found this:
http://forum.cmsmadesimple.org/index.ph ... 475.0.html
So now I have a user defined tag called {canonical} that's in my template. That works.
I changed my ArticleDetail template according to the article above, changed my template, got rid of {process_pagedata} in my normal template, added the {content assign="capturedcontent"} on the first line and changed {content} to {capturedcontent}. I also replaced the  with the line from the article above.
Now my article title sits nicely in my Title. But still, when I check the source of my article the  gives the detail page info of my landing page, but no info about the article I'm viewing.
By the way, my canonical tag look like this:
Code: Select all
global $gCms;
if ($gCms->variables['page_name'] !='') {
	$manager =& $gCms->GetHierarchyManager();
	$node =& $manager->sureGetNodeByAlias($gCms->variables['page_id']);
	
	$content =& $node->GetContent();
	if (isset($content) && is_object($content))
	{
		if ($content->GetURL() != '')
		{
		echo '<link rel="canonical" href="'.$content->GetURL().'" />';
		}
	}
}
 
			
					
				Re: Canonical link for news articles
				Posted: Mon Sep 14, 2009 6:08 am
				by Guido
				Update:
As I was checking my google errors I found out why the above was important. It prevents double title serrors right?
			 
			
					
				Re: Canonical link for news articles
				Posted: Mon Sep 14, 2009 7:54 am
				by RonnyK
				Guido,
for my information.... 3 things are needed for the News canonical links in the source.
1) process_whole_template = false (in config.php)
2) Page template should have logic inside head-block:
{if isset($canonical)}{elseif isset($content_obj)}GetURL()}" />{/if}
These 2 already make the regular content-pages have canonical links.
3) Detail template of News should have canonical logic:
{* set a canonical variable that can be used in the head section if process_whole_template is false in the config.php *}
{if isset($entry->canonical)}
  {assign var='canonical' value=$entry->canonical}
{/if}
I tested and with these settings the News-detailpages have the canonical link inside...
Ronny
 
			
					
				Re: Canonical link for news articles
				Posted: Mon Sep 14, 2009 4:23 pm
				by Guido
				Works like a charm, thanks.