Page 1 of 1
Adding meta description to every newsarticle
Posted: Tue Jun 06, 2017 8:11 am
by babel
I'm looking for a way to add a meta description to every article in the news-module. Googling this question was to no avail. I found
https://www.i-do-this.com/blog/Put-your ... topilot/57 but that was not the solution.
I'm using cms ms 2.1.2 and news 2.50.4
I hope this enough information to help me out.
Re: Adding meta description to every newsarticle
Posted: Tue Jun 06, 2017 9:02 am
by Rolf
Re: Adding meta description to every newsarticle
Posted: Tue Jun 06, 2017 12:09 pm
by babel
Thanks Rolf for the link, but it's not what I'm looking for. With ordinary pages you can add meta data under the tab Logica. Something similar but for each newsarticle is what I would like. It means that for example there is an option in Article to add a meta description. Should explained this in the first place, but never to late I hope.
Re: Adding meta description to every newsarticle
Posted: Tue Jun 06, 2017 12:27 pm
by Rolf
You still can use the tutorial, but add an extra text field for the meta description...
Re: Adding meta description to every newsarticle
Posted: Tue Jun 06, 2017 2:40 pm
by scooper
As Rolf says you can add a custom field if you want to keep things separate. We normally just use the summary field that's already there - so in our detail template we have something like
Code: Select all
{if $entry->summary}
{$meta_descr=$entry->summary|truncate:'150'|strip_tags|strip scope="global"}
{/if}
and then in our page template something like
Code: Select all
{if isset($meta_descr)}
<meta name="description" content="{$meta_descr}" />
{else}
whatever else you want to show.
{/if}
Re: Adding meta description to every newsarticle
Posted: Wed Jun 07, 2017 10:44 am
by babel
Rolf and Scooper, thanks for your help, but I can't get it working. What I think I'm doing wrong, I don't know. So let it rest. Metatags aren't not very important anymore.
Re: Adding meta description to every newsarticle
Posted: Wed Jun 07, 2017 12:42 pm
by velden
I don't agree. And if it's not meta description it could be social media meta tages, page title etc etc.
You might want to post your news detail template and your page template.
Re: Adding meta description to every newsarticle
Posted: Wed Jun 07, 2017 6:06 pm
by babel
This is the code in my page template. It's name is "blog".
Code: Select all
{strip}
{process_pagedata}
{$canonical_url = "{$content_obj->GetURL()|lower|default:''}" scope=global}
{$root_url = "{root_url}" scope=global}
{$theme_url = "{uploads_url}/_template"}
{$site_name = "{sitename}" scope=global}
{$page_description = "{description}" scope=global}
{$page_image = "{$theme_url}/page_image.png" scope=global}
{$page_lang = 'en' scope=global}
{$page_modified = "{modified_date format='%e-%m-%Y'}" scope=global}
{$page_title = "{title}" scope=global}
{if isset($meta_descr)}
<meta name="description" content="{$meta_descr}" />
{else}
{/if}
<!doctype html>
<__html lang="en">
<head>
<title>{title} - {sitename}</title>
{metadata}
{cms_stylesheet}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
{literal}<__script__>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-77232848-1', 'auto');
ga('send', 'pageview');
</__script>
{/literal}
</head>
</__body>
<div class="google_code">google-site-verification: google101bc51642bac903.html</div>
<!-- Google Tag Manager -->
{literal}<noscript><__iframe src="//www.googletagmanager.com/ns.html?id=GTM-MK4C5Z"
height="0" width="0" style="display:none;visibility:hidden"></__iframe></noscript>
<__script__>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MK4C5Z');</__script>
<!-- End Google Tag Manager -->{/literal}
<div class="container">
<header class="header">
<div class="logo">
{page_attr page="html-blokken" key="logo"}
</div>
<section class="img_header">
<figure><img src="images/gebouw_villa.jpg" alt="locatie ag-zaalhuur"/></figure>
</section>
{page_attr page="html-blokken" key="lees_blog"}
</header>
<input type="checkbox" id="nav_main"/><label for="nav_main">menu</label>
<nav class="main_nav">
{Navigator template="minimal_menu"}
</nav>
<section class="main">
{content}
</section><!--main-->
<footer class="footer">{page_attr page="html-blokken" key="content_en"} </footer>
</div><!--container-->
<section class="balk_info">
<div class="balk_wrap">
<h2>AG ZAALVERHUUR IN BIJZONDERE AMBIANCE</h2>
<div class="top_links"><a href="mailto:info@ag-zaalverhuur.nl">INFO@AG-ZAALVERHUUR.NL</a>
<a href="tel:+31402434808">040 2434808</a></div>
</div><!--balk_wrap-->
</section><!--balk_info-->
<__body>
</__html>
{/strip}
The code of News Detail Sample is
Code: Select all
{$canonical_url = $entry->canonical|lower scope=global}
{$page_description = $entry->summary|default:$entry->content|strip_tags|strip|truncate:150 scope=global}
{$page_modified = $entry->modified_date|date_format:'%e-%m-%Y' scope=global}
{$page_title = $entry->title|cms_escape:htmlall scope=global}
{if $entry->summary}
{$meta_descr=$entry->summary|truncate:'150'|strip_tags|strip scope="global"}
{/if}
{* News module entry object reference:
------------------------------
In previous versions of News the 'object' returned in $entry was quite simple, and a <pre>{$entry|@print_r}</pre> would output all of the available data
This has changed in News 2.12, the object is not quite as 'simple' as it was in previous versions, and that method will no longer work. Hence, below
you will find a referennce to the available data.
====
news_article Object Reference
====
Members:
--
Members can be displayed by the following syntax: {$entry->membername} or assigned to another smarty variable using {assign var='foo' value=$entry->membername}.
The following members are available in the entry array:
id (integer) = The unique article id.
author_id (integer) = The userid of the author who created the article. This value may be negative to indicate an FEU userid.
title (string) = The title of the article.
summary (text) = The summary text (may be empty or unset).
extra (string) = The "extra" data associated with the article (may be empty or unset).
news_url (string) = The url segment associated with this article (may be empty or unset).
postdate (string) = A string representing the news article post date. You may filter this through cms_date_format for different display possibilities.
startdate (string) = A string representing the date the article should begin to appear. (may be empty or unset)
enddate (string) = A string representing the date the article should stop appearing on the site (may be empty or unset).
category_id (integer) = The unique id of the hierarchy level where this article resides (may be empty or unset)
status (string) = either 'draft' or 'published' indicating the status of this article.
author (string) = The username of the original author of the article. If the article was created by frontend submission, this will attempt to retrieve the username from the FEU module.
authorname (string) = The full name of the original author of the website. Only applicable if article was created by an administrator and that information exists in the administrators profile.
category (string) = The name of the category that this article is associated with.
canonical (string) = A full URL (prettified) to this articles detail view using defaults if necessary.
fields (associative) = An associative array of field objects, representing the fields, and their values for this article. See the information below on the field object definition. In past versions of News this was a simple array, now it is an associative one.
customfieldsbyname = (deprecated) - A synonym for the 'fields' member
fieldsbyname = (deprecated) - A synonym for the 'fields' member
useexp (integer) = A flag indicating wether this article is using the expiry information.
file_location (string) = A url containing the location where files attached the article are stored... the field value should be appended to this url.
====
news_field Object Reference
====
The news_field object contains data about the fields and their values that are associated with a particular news article.
Members:
--------
id (integer) = The id of the field definition
name (string) = The name of the field
type (string) = The type of field
max_length (integer) = The maximum length of the field (applicable only to text fields)
item_order (integer) = The order of the field
public (integer) = A flag indicating wether the field is public or not
value (mixed) = The value of the field.
====
Below, you will find the normal detail template information. Modify this template as desired.
*}
{* 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)}
{* note this syntax ensures that the canonical variable is set into global scope *}
{assign var='canonical' value=$entry->canonical scope=global}
{/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" />-->
{if $entry->summary}
<div id="NewsPostDetailSummary">
{$entry->summary}
</div>
{/if}
{if $entry->category}
<div id="NewsPostDetailCategory">
{$category_label} {$entry->category}
</div>
{/if}
<!--{if $entry->author}
<div id="NewsPostDetailAuthor">
{$author_label} {$entry->author}
</div>
{/if}-->
<div id="NewsPostDetailContent">
{$entry->content}
</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'}
<div class="NewsDetailField">
{if $field->type == 'file'}
{* this template assumes that every file uploaded is an image of some sort, because News doesn't distinguish *}
{if isset($field->value) && $field->value}
<img src="{$entry->file_location}/{$field->value}"/>
{/if}
{else}
{$field->name}: {$field->value}
{/if}
</div>
{/foreach}
{/if}
I hope this wil be an help to help me.
Re: Adding meta description to every newsarticle
Posted: Wed Jun 07, 2017 8:37 pm
by velden
Yes, the part with the <meta ... Tag needs to be inside the <head> section, not in the top.
Re: Adding meta description to every newsarticle
Posted: Wed Jun 07, 2017 8:59 pm
by Rolf
You really should have read my whole tutorial. It is all there!!
Re: Adding meta description to every newsarticle
Posted: Thu Jun 08, 2017 7:41 am
by babel
I thank you all for your help. I had to finetune a little, so that the field extra is now for meta.