Meta tag DESCRIPTION

Meta tag DESCRIPTION

Postby italian_user on Sat Sep 26, 2009 9:33 am

Good morning,
since some year I try to put the meta tag description in my template, but I can't do it!

Now I put the static
<meta name="description" content="description of my blog" />
but it's STATIC!

How I can do to make it dinamic?

For example:

Title article: Good morning
Text article: Welcome to my blog, finally I have a new fantastic blog

I'd like that in the blog online, if you read the "html source", in the description You can read the first "20 characters"...
<meta name="description" content="Welcome to my blog" />

Is it possible?

I have a friend who use the word press and He use the
" All in One SEO Pack 1.6.4 by Michael Torbert of Semper Fi Web Design[876,917] "
This automatically creates the description and the tags for every article!

Is there also for LifeType?

thanks very much
italian_user
 
Posts: 193
Joined: Mon Apr 03, 2006 1:37 pm
LifeType Version: 1.2.11

Re: Meta tag DESCRIPTION

Postby jondaley on Mon Sep 28, 2009 9:09 am

The meta tags can be generated by simply putting:

{$post->getText()|truncate:20:"..":true|strip_tags|escape}

in your template.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby jondaley on Mon Sep 28, 2009 9:16 am

I figured I'd check it out on my own blog to see what I think. Here is what I added to my blog:

Code: Select all
{if $OnMainPage}                                                                                                                             
  <meta name="description" content="Main page description..." />                                                                                                       
  {elseif $post}                                                                                                                               
  <meta name="description" content="{$post->getText()|truncate:150:"..":false|strip_tags}" />                                                 
{/if}


(note, you need to set the $OnMainPage appropriately for your site.
I simply use
Code: Select all
{assign var="OnMainPage" value=1}

in main.template for my blog, but on some sites I've done fancier things.

[EDIT: 12/2011, see the post further down for a better example]
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby jondaley on Mon Sep 28, 2009 9:18 am

(and is that really all the All in one seo pack plugin does? I have a customer who recently installed it, and had quite a bit of trouble with it, and we had to figure out some SQL queries to generate the tags appropriately.

And if that is all it does - this is yet another reason I love LifeType - a new feature that the developers never thought of can be implemented with 30 seconds of thinking)
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby italian_user on Mon Sep 28, 2009 10:09 am

thanks very much, you are ever very kind!

THANKS!
italian_user
 
Posts: 193
Joined: Mon Apr 03, 2006 1:37 pm
LifeType Version: 1.2.11

Re: Meta tag DESCRIPTION

Postby easyexpat on Wed Nov 23, 2011 8:24 am

I have implemented this change, as I have just noticed today that there was not description by default in the templates :-(

But I have made a small change:
Code: Select all
<meta name="description" content="{$post->getText()|strip_tags|truncate:150:"..":false}"

You better strip the tags before to truncate, otherwise you might just truncate the html tag and as a result put nothing in description (in my case i have images starting most of the posts).
:geek:
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Meta tag DESCRIPTION

Postby jondaley on Sun Nov 27, 2011 7:14 pm

Yes, at some point along the way, I fixed that bug, but didn't realize I had pasted it here as an example.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby jondaley on Fri Dec 02, 2011 12:18 am

Here's my current version:
Code: Select all
  {if $OnMainPage}
    {assign var="description" value="Description for the main page..."}
    {if $category && $category->getDescription()}
      {assign var="description" value=$category->getDescription()}
    {/if}
  {elseif $post}
    {assign var="description" value=$post->getText()|strip_tags|truncate:150:"..":false}
  {/if}
  <meta name="description" content="{$description}" />
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby easyexpat on Fri Dec 02, 2011 5:26 am

jondaley wrote:Here's my current version:
Code: Select all
  {if $OnMainPage}
    {assign var="description" value="Description for the main page..."}
    {if $category && $category->getDescription()}
      {assign var="description" value=$category->getDescription()}
    {/if}
  {elseif $post}
    {assign var="description" value=$post->getText()|strip_tags|truncate:150:"..":false}
  {/if}
  <meta name="description" content="{$description}" />

Thanks. Adding the part on category is a nice feature indeed. :ugeek:
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Meta tag DESCRIPTION

Postby jondaley on Sat Dec 10, 2011 2:01 pm

Oops, found a bug in it today, when I had a quote mark in my post. Just added "escape" to the post->getText().
Code: Select all
 {if $OnMainPage}
    {assign var="description" value="this is a generic description for the main page"}
    {if $category && $category->getDescription()}
      {assign var="description" value=$category->getDescription()}
    {/if}
    <meta name="keywords" content="blah, blah, blah," />
  {elseif $post}
    {assign var="description" value=$post->getText()|strip_tags|escape|truncate:150:"..":false}
  {/if}
  <meta name="description" content="{$description}" />
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby easyexpat on Sat Dec 10, 2011 6:11 pm

jondaley wrote:Oops, found a bug in it today, when I had a quote mark in my post. Just added "escape" to the post->getText().

Thanks for the update, I've implemented the fix.
Last edited by easyexpat on Sat Dec 10, 2011 7:16 pm, edited 1 time in total.
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Meta tag DESCRIPTION

Postby easyexpat on Sat Dec 10, 2011 7:16 pm

Euh, not good. I get more html code instead with &amp:
Before the change
Code: Select all
My name is Caroline.&nbsp; I&rsquo;m an American

After
Code: Select all
My name is Caroline.&amp;nbsp; I&amp;rsquo;m an American


Therefore it is worse...
I managed to avoid the problem with
Code: Select all
{assign var="description" value=$post->getText()|strip_tags|strip|replace:"&nbsp;":" "|replace:"&rsquo;":" "|replace:"&#039;":" "|replace:"&eacute;":"é"|replace:"&egrave":"è"|replace:"&ecirc":"ê"|replace:"&agrave;":"à"|replace:"&ugrave;":"ù"|replace:"&icirc;":"î"|escape|truncate:150:"...":false}

(I kept escape just in case...)

I know it should be a long list of replace, such as with ø, û etc... but it will do in the meantime. :ugeek:
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Meta tag DESCRIPTION

Postby jondaley on Mon Dec 12, 2011 12:35 pm

Hrm. There must be a better way to do that then. Maybe just remove or escape the quotes? And leave all of the rest?
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby jondaley on Mon Dec 12, 2011 12:43 pm

How about this:
Code: Select all
{assign var="description" value=$post->getText()|strip_tags|replace:'"':'\''|truncate:150:"..":false}


Getting more ugly...
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Meta tag DESCRIPTION

Postby easyexpat on Tue Dec 13, 2011 5:15 am

jondaley wrote:How about this:
Code: Select all
{assign var="description" value=$post->getText()|strip_tags|replace:'"':'\''|truncate:150:"..":false}


Getting more ugly...

I haven't tried this one but this is fixing only the ugly char generated by escape. &nbsp etc are still there and therefore need to be replaced too. :?
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Next

Return to Templates

cron