CMS MADE SIMPLE FORGE

SEOTools2

 

[#9725] SEOTools2 Module does not recognise news pages

avatar
Created By: dave (enxdtw)
Date Submitted: Thu Dec 12 14:14:50 -0500 2013

Assigned To: Prue Rowland (psy)
Version: 1.2.1
CMSMS Version: 1.11.9
Severity: Minor
Resolution: Invalid
State: Open
Summary:
SEOTools2 Module does not recognise news pages
Detailed Description:
SEOTools is a great module maybe one of the best, however I am finding that the
news pages are not being recognized, although news items contain lots of SEO
content (and often updated) they are tagged with the content from their parent
page which in my case seems to be home. That also means that the tags are being
duplicated for each news item page ( which is not good for SEO), whereas I would
rather be able to set the tags myself for each news item in the SEOTools 'page
settings' page. Is there a work around?

Cheers

Dave


History

Comments
avatar
Date: 2013-12-12 16:40
Posted By: Prue Rowland (psy)

There is! 

You need to create two custom fields in News (or cgblog, ListIt2 or whatever
module has detail pages) - keywords and metadescription. In SEO2, you tell the
module what the keyword field name is, eg "detail_keywords", then in the detail
page template, assign your custom field value to 'detail_keywords', eg (for
ListIt2 module):

{if $item->fielddefs.metadescription.value != ''}
{assign var=metadescription value=$item->fielddefs.metadescription.value}
{/if}	

For the metadescription, you need to put in your page template:

{if empty($metadescription)}
{content block=metadescription label="Page META description" oneline='true'
assign='metadescription'}
{/if}
{if !empty($metadescription)}

Ensure that this appears at the bottom of the template. In your module assign
your metadescription custom field to 'metadescription'. The detail page
metadescription var will then override the parent page value.

The above will ensure that all detail pages (News, Blog, LI2, etc) will have
their own keywords and meta description.

Hope this helps

      
avatar
Date: 2013-12-12 16:43
Posted By: Prue Rowland (psy)

Correction, in your detail template:

{assign var=detail_keywords value=$item->fielddefs.keywords->value}

{if $item->fielddefs.metadescription.value != ''}
{assign var=metadescription value=$item->fielddefs.metadescription.value}
{/if}	

      
avatar
Date: 2013-12-13 10:31
Posted By: dave (enxdtw)

Thanks for the info, I saw the "Module custom field keywords Smarty var:" before
but didn't know how to use it.

this is what I did ...

On the news page in the "field definitions tab"

I added the two field definitions: 

keywords , metadescription

then on the news->"detail template" tab, I opened the default template
(simplex_detail) and added the following code at the bottom of the template

{assign var=detail_keywords value=$item->fielddefs.keywords->value}

{if $item->fielddefs.metadescription.value != ''}
{assign var=metadescription value=$item->fielddefs.metadescription.value}
{/if}	

In the SEOTools2 Module page title and meta information I added 

detail_keywords to the 

"Module custom field keywords Smarty var:" field

Then I added to layout->templates->simplex page template ...

{if empty($metadescription)}
{content block=metadescription label="Page META description" oneline='true'
assign='metadescription'}
{/if}


to the bottom of the main page template, I think there was a mistake in your
code as {if !empty($metadescription)} causes an error.

But it doesn't work, if I look at the page source for the news item I get the
keywords and metadescription from the parent page, which is non-specific to the
new item.

Cheers

Dave


      
avatar
Date: 2013-12-13 16:23
Posted By: Prue Rowland (psy)

Are you using the correct notation for accessing the News custom fields?  The
exampleI gave was for a ListIT2 custom module.

For starters, the News module by default uses $entry instead of $item.

You should test that you're getting the correct custom field values by
outputting them to the page first as a test.
      
avatar
Date: 2013-12-14 13:25
Posted By: dave (enxdtw)

you have to make the fields public to be recognised by SEOTools for some reason,
then use code like this in the detail template, however making the fields public
also causes the data keywords and metadata variables to be displayed by the news
module!

{assign var=detail_keywords value=$entry->fields.keywords->value}

{if $entry->fields.metadescription->value != ''}
{assign var=metadescription value=$entry->fields.metadescription->value}
{/if}	
      
avatar
Date: 2013-12-14 13:30
Posted By: dave (enxdtw)

In the end I had to do a

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     {if $field->name === 'metadescription' || $field->name === 'keywords'} 
        {continue} 
     {/if} 

in the news detail template, oh well its working now, At least until the news
module gets updated!

Cheers

Dave
      
avatar
Date: 2013-12-14 14:22
Posted By: dave (enxdtw)

I am still unable to get the title tag to show even though I add

{assign var='alt_title' value=$entry->title}

to the end of the detail template, as part of the SEOtools installation I was
told by the help to replace

{if isset($alt_title)}
<title>{sitename} - {$alt_title}</title>
{else}
<title>{sitename} - {title}</title>
{/if}

with 

{SEOTools2}

so I would have thought it would work with the alt_title.

Cheers

Dave
      
avatar
Date: 2013-12-14 14:37
Posted By: dave (enxdtw)

Result! I did it with 

{($alt_title)?$alt_title:$title} 

in the SEOtools2 page title field
      
avatar
Date: 2013-12-14 14:49
Posted By: dave (enxdtw)

correction the code should have been

{($alt_title !== null)?$alt_title:{title}} 
      
avatar
Date: 2013-12-14 15:21
Posted By: Prue Rowland (psy)

Excellent!

Yes, the fields must be public to be used anywhere in the frontend template and
you were correct to edit the template to not show them.  I assume you copied the
sample template, edited it and then made it the default.  Otherwise if you
edited the original detail template, you could lose the changes in an upgrade.



      
avatar
Date: 2014-01-10 04:42
Posted By: Bauke Jonkmans (BaukeJ)

Hi Dave or Psy,

I have the same problem. When reading both your comments to this thread, i have
come to the following code for my dtail page in the News module:
--
{* 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}

{if $entry->postdate}
	<div id="NewsPostDetailDate">
		{$entry->postdate|cms_date_format}
	</div>
{/if}
<h3 id="NewsPostDetailTitle">{$entry->title|cms_escape:htmlall}</h3>

<hr id="NewsPostDetailHorizRule" />
<div class="fb-like" data-href="{$canonical}" data-layout="standard"
data-width="70" data-action="like" data-show-faces="true"
data-share="true"></div>
{if $entry->summary}
	<p><div id="NewsPostDetailSummary">
		<strong>
			{eval var=$entry->summary}
		</strong>
	</div>
{/if}
<br>
<div id="NewsPostDetailContent">
	{eval var=$entry->content}</p>
{if $entry->bron}
		Bron: {$entry->bron}
{/if}
</div>

{if $entry->extra}
	<div id="NewsPostDetailExtra">
		{$extra_label} {$entry->extra}
	</div>
{/if}


{if $return_url != ""}
<div id="NewsPostDetailReturnLink">{$return_url}{if $category_name != ''} -
{$category_link}{/if}</div>
{/if}

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
        {if $field->name === 'metadescription' || $field->name === 'keywords'} 
        {continue} 
        {/if} 	
     <div class="NewsDetailField">
        {if $field->type == 'image'}
{* this template assumes that every file uploaded is an image of some sort,
because News doesn't distinguish *}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}
{if empty($metadescription)}
  {content block=metadescription label="Page META description" oneline='true'
  assign='metadescription'}
{/if}
{($alt_title !== null)?$alt_title:{title}}

--
Also i have taken the other actions; creating the alternate (public) field
definitions in News (keywords, metadescription) and I entered "detail_keywords"
to the "module custom field keywords Smarty var" field in SeoTools2.

Could you help me, is there anything i have forgotten or did I do something
wrong?
      
avatar
Date: 2014-01-10 05:23
Posted By: dave (enxdtw)

Hi Bauke,

Here is my  news detail template ...

{assign var=detail_keywords value=$entry->fields.keywords->value}

{if $entry->fields.metadescription->value != ''}
     {assign var=metadescription value=$entry->fields.metadescription->value}
{/if}	

{* 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}

<h2>{$entry->title|cms_escape:htmlall}</h2>
{if $entry->summary}
    {eval var=$entry->summary}
{/if}
    {eval var=$entry->content}
{if $entry->extra}
		{$extra_label} {$entry->extra}
{/if}
{if $return_url != ""}
    <br />
<span class='back'>← {$return_url}{if $category_name != ''} -
{$category_link}{/if}</span>
{/if}

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     {if $field->name === 'metadescription' || $field->name === 'keywords'} 
        {continue} 
     {/if} 
     <div>
        {if $field->type == 'file'}
{* this template assumes that every file uploaded is an image of some sort,
because News doesn't distinguish *}
          <img src='{$entry->file_location}/{$field->value}' alt='' />
        {else}
          {$field->name}: {eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}
    <footer class='news-meta'>
    {if $entry->postdate}
        {$entry->postdate|cms_date_format}
    {/if}
    {if $entry->category}
        <strong>{$category_label}</strong> {$entry->category}
    {/if}
    {if $entry->author}
        <strong>{$author_label}</strong> {$entry->author}
    {/if}

    </footer>

{assign var='alt_title' value=$entry->title}

      
avatar
Date: 2014-01-10 06:40
Posted By: Bauke Jonkmans (BaukeJ)

HiDave,

Thanks for you reply. Nice example!

Using your code it works like a charm. I altered my template and now I see that
i used the wrong places for some code, Thank you very much.

Does the title in the meta work with your template? As far as I can see it
doesn't

Grtz

Bauke
      
avatar
Date: 2014-01-10 06:43
Posted By: dave (enxdtw)

You need something like the following in the seotools2 page 

Page title:

{$sitename} - extended title | {($alt_title !== null)?$alt_title:{title}} 

Cheers

Dave
      
avatar
Date: 2014-01-10 06:57
Posted By: Bauke Jonkmans (BaukeJ)

Thanks Dave!
      
Updates

Updated: 2013-12-12 16:40
resolution_id: => 9