[Solved] Canonical link for news articles

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

[Solved] Canonical link for news articles

Post 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?
Last edited by Guido on Mon Sep 14, 2009 4:23 pm, edited 1 time in total.
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: Canonical link for news articles

Post 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
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: Canonical link for news articles

Post by Guido »

proces_whole_template isn't even in my config.php. Could I just add it?
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: Canonical link for news articles

Post 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.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: Canonical link for news articles

Post 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().'" />';
		}
	}
}
Last edited by Guido on Sun Sep 13, 2009 3:26 pm, edited 1 time in total.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: Canonical link for news articles

Post by Guido »

Update:

As I was checking my google errors I found out why the above was important. It prevents double title serrors right?
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: Canonical link for news articles

Post 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
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: Canonical link for news articles

Post by Guido »

Works like a charm, thanks.
Post Reply

Return to “CMSMS Core”