Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-05-17 19:13:23

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Excepts stripped of markup (for meta descriptions)

Hi,

How can I print excepts stripped of markup?

<meta name="description" value="Except without <html>markup</html>, please.">

I use excepts with markup several places on my site. But in the example above, I would like it without the markup.

Offline

#2 2007-05-17 19:26:00

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Excepts stripped of markup (for meta descriptions)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2007-05-17 19:27:04

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excepts stripped of markup (for meta descriptions)

<meta name="description" value="<txp:php>echo strip_tags(excerpt(array()));</txp:php>">

Offline

#4 2007-05-17 19:44:47

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Excepts stripped of markup (for meta descriptions)

Thanks, Ruud. :) Does that work with all txp tags?

Offline

#5 2007-05-17 19:58:58

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Excepts stripped of markup (for meta descriptions)

maniqui wrote:

You can do this:
http://sonspring.com/journal/lazy-textpattern-seo

Thanks maniqui for this link. Until now I used a custom field for the description, but often forgot to fill it. This method is perfect!

Offline

#6 2007-05-17 19:59:27

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excepts stripped of markup (for meta descriptions)

It should work with all TXP tags that output (X)HTML code

Offline

#7 2007-05-17 21:29:30

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Excepts stripped of markup (for meta descriptions)

Can someone spot my syntax error?

<meta name="description" content="<txp:php>if excerpt(array()) {
   echo(strip_tags(excerpt(array()));
} else {
   echo("Default description."); }</txp:php>">

Offline

#8 2007-05-17 21:36:51

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excepts stripped of markup (for meta descriptions)

Add ( ) around the “if” condition and add another closing ) at the end of the strip_tags line, just before the semicolon.

PS. this is shorter:

<meta name="description" content="<txp:php>echo (excerpt(array()) ? strip_tags(excerpt(array())) : 
'Default description.');</txp:php>">

Last edited by ruud (2007-05-17 21:40:35)

Offline

#9 2007-06-04 01:20:25

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Excepts stripped of markup (for meta descriptions)

I cannot see why this code does not work. Anyone spotting my error? A shorter version would be appriciated too!

<meta name="description" content="<txp:php>if (except(array())) {
echo(strip_tags(excerpt(array()));
echo(' There are '); echo(comments_count(array)); echo(' comments.'); }
else { echo('Default description.'); }</txp:php>">

Last edited by Aleksandersen (2007-06-04 01:20:56)

Offline

#10 2007-06-04 04:32:38

FireFusion
Member
Registered: 2005-05-10
Posts: 698

Re: Excepts stripped of markup (for meta descriptions)

Good topic

Offline

#11 2007-06-04 05:03:49

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Excepts stripped of markup (for meta descriptions)

Your first line says except rather than excerpt.

Offline

#12 2007-06-04 06:40:05

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excepts stripped of markup (for meta descriptions)

daniel, you’ve made a typo, it’s “excerpt”, not “except” and on the second line you have one “)” too many.

PS. you don’t need “( )” around things you want to echo.

Offline

Board footer

Powered by FluxBB