SEOTools2 with detail pages

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

SEOTools2 with detail pages

Post by psy »

SEOTools2 is designed to output keywords and meta descriptions for entire pages. That doesn't quite work when you have a detail page, eg News, CGBlog, Products etc.

You can replace the standard page meta by following a few simple steps.

For each of the modules that have detail pages, create two custom fields. Call them what you will so long as they are the same across all the modules, eg 'detail_keywords' and 'metadescription'.

At the end of your detail template, put:

Code: Select all

{assign var=metadescription value=$entry->fields.metadescription->value}
{assign var=detail_keywords value=$entry->fields.detail_keywords->value
Or whatever the semantics are for retrieving the custom field value for the module.

This makes those vars available to the entire page, not just the individual modules.

Next, at the bottom of your page template, enter:

Code: Select all

{if !isset($metadescription)}{content block='metadescription' label='Page description for SEO' oneline='true'}{/if}
This will retain the detail page's metadescription rather than replacing it with the page's metadescription. The var name must match the name of the content_block you've nominated as the content block for the meta description in SEOTools2.

Next, in SEOTools2, wherever you have the {keywords} tag, say:

Code: Select all

{if isset($detail_keywords)}{$detail_keywords}{else}{keywords}{/if}
In other words, replace the page keywords with the detail page keywords.

Although they only appear as single line fields, the SEOTools2 page title and meta title fields have full Smarty template processing capabilities.

Of course this will only work when the config process_whole_template is set to false. The body html must be processed before the head stuff.

Have fun with this,
psy
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: SEOTools2 with detail pages

Post by psy »

Another way to use your assigned var {$metadescription} which definitely works with CMSMS 1.11+:

Make all the modifications as above in the detail and page templates with the following change to the {SEOTools2} tag in the <head> section:

Code: Select all

{capture assign='seo2'}{SEOTools2}{/capture}
{if strpos($seo2,$metadescription) !== false}
{$seo2}
{else}
{assign var=newtag value="<meta name='description' content='"|cat:$metadescription|cat:"'>"}
{assign var='start' value=$seo2|strpos:"<meta name='description'"}
{assign var='endoftag' value=$seo2|strpos:">":$start}
{assign var='length' value=$endoftag-$start+1}
{$seo2|substr_replace:$newtag:$start:$length}
{/if}
What it does is firstly check to see if the {$metadescription} tag is the same as what SEOTools2 outputs. If so, no problem.

Otherwise it replaces the <meta name='description' content='whatever is assigned on the actual page' > with a new tag that includes the $metadescription assigned in the detail template.

PS: Remember to change |cat:"'>"} to |cat:"' />"} if you're using XHTML.
nidus
Forum Members
Forum Members
Posts: 23
Joined: Tue Apr 22, 2008 2:54 pm
Location: Toronto

Re: SEOTools2 with detail pages

Post by nidus »

how about keywords?
the tag {keywords} is no longer there. Now we have {seo_keywords}
Locked

Return to “Tips and Tricks”