Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-02-14 15:10:22

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

[howto] customizing (per article) the "read more" links after excerpt

Hi.
This snippet can be used to have different text in the permlink after an excerpt.
It has been inspired by this FAQ, this article in Freshly Pressed, and by some features in the beginning plug-in (plug-in not needed for this tag example)

Basically, the idea is to have a custom field where you can add the text you want for your “read more” link. If no text is added, then simple display a read more link

1. go to Advanced Preferences and name a custom field “continue” (w/o quotes)

<h3><txp:permlink><txp:title /></txp:permlink> | <small><txp:posted /></small></h3>
<txp:if_article_list>
<!-- here comes the relevant part of this tag example -->
<txp:if_excerpt>
<txp:excerpt />
<txp:permlink>
<txp:if_custom_field name="continue">
<txp:custom_field name="continue" />
<txp:else />	
read more
</txp:if_custom_field>
</txp:permlink>
<!-- and finish here -->
<txp:else />
<txp:body />
</txp:if_excerpt>
<txp:else />
<txp:body />
</txp:if_article_list>

What we are saying (between the comments) with the above snippet is:
“If there is an excerpt, show the excerpt. Then, open the permalink and fill it: if there is something in the custom field ‘continue’ return the content of that custom field. Else, return ‘read more’. Then close the permlink.”

Easy, isnt it?
Of course, you can create more “complex” versions of snippets, like:

<txp:if_excerpt>
<txp:excerpt />
<p class="readmore"><txp:permlink>
<txp:if_custom_field name="continue">
<txp:custom_field name="continue" /> 
<txp:else />	
read more
</txp:if_custom_field>
</txp:permlink></p>

or like

<code><txp:if_excerpt></code>
<code><txp:excerpt /></code>
<code><txp:if_custom_field name=“continue”></code>
<code><a href=”<txp:permlink />” title=“more about <txp:title />”><txp:custom_field name=“continue” /></a></code>
<code><txp:else /></code>
<code><txp:permlink>read more</txp:permlink></code>
<code></txp:if_custom_field></code>

<br />

<small>edit*</small>: Of course: *remember to close all the “txp:if” tags that I didnt close

That’s all.
If you have new ideas around this snippets, come and share them! thanks.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2006-06-21 03:02:23

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

Re: [howto] customizing (per article) the "read more" links after excerpt

Well, today I learned a new thing: the <txp:permlink></txp:permlink> seems to work fine inside the excerpt field in the Write tab.

So, you can have customized read more links directly in your excerpt paragraph, doing something like:

<code>This is the excerpt of the most cool article. <txp:permlink>read the coolest article!</txp:permlink>
</code>
Anyone (devs?) knows if this can be problematic in anyway?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2006-06-21 03:09:41

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

Re: [howto] customizing (per article) the "read more" links after excerpt

Ah, I forgot to tell one advantage of using the <txp:permlink></txp:permlink> inside the excerpt field: it’s an easy way to have inline “read more” links.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2010-01-21 11:43:22

hans maulwurf
New Member
Registered: 2010-01-21
Posts: 4

Re: [howto] customizing (per article) the "read more" links after excerpt

Well, this thread is old, I know.

But does anyone have an idea how to hide the read more link if there is only a excerpt for the article?

I tried this without any success:

<txp:if_variable body="">
<txp:else />
<p class="readMore">
<txp:permlink>read more...</txp:permlink>
</txp:if_variable>

Offline

#5 2010-01-21 12:13:59

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: [howto] customizing (per article) the "read more" links after excerpt

Hi,
this should work provided you previously set the body variable:

<txp:variable name="body" value='<txp:body />' />

edit: changed double quotes to single quotes, for tags in tags to work (maniqui)

edit again: thank you maniqui but I don’t think it was necessary given that the “txp:body” tag doesn’t have attributes so doesn’t contains double quotes itself

Last edited by redbot (2010-01-22 03:17:50)

Offline

#6 2010-01-21 15:50:58

hans maulwurf
New Member
Registered: 2010-01-21
Posts: 4

Re: [howto] customizing (per article) the "read more" links after excerpt

Thanks for your fast answers, but it does not work yet.

Interestingly it even does not work if I use excerpt to fill the variable “body”

Where do I have to fill the variable at all? Do I have to adhere something?

This is what I have so far:

<txp:if_individual_article>
<p class="published"><txp:posted /></p>
<h1 class="entry-title"><txp:permlink><txp:title /></txp:permlink></h1>
<h2><txp:excerpt /></h2>
<txp:body />

<txp:else />

<p class="published"><txp:posted /></p>
<h3 class="entry-title"><txp:permlink><txp:title /></txp:permlink></h3>
<div class="entry-content">
<txp:excerpt />
<txp:variable name="body" value='<txp:body />' />
<txp:if_variable body="">
<txp:else />
<p class="readMore">
<txp:permlink>read more...</txp:permlink>
</txp:if_variable>
</p>
</div>
</txp:if_individual_article>

Offline

#7 2010-01-21 16:04:36

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [howto] customizing (per article) the "read more" links after excerpt

Change

<txp:if_variable body="">

to

<txp:if_variable name="body">

Code is topiary

Offline

#8 2010-01-21 19:51:09

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

Re: [howto] customizing (per article) the "read more" links after excerpt

To be more precise:

<txp:if_variable name="body" value="">
<txp:else />
// read more link here
</txp:if_variable>

If you use just <txp:if_variable name="body"> you are testing for the existence of the variable, and even when its value is empty it always exists, because you set it with the <txp:variable name="body" /> tag. So you need to check if has a value or not.

Offline

#9 2010-01-21 20:50:12

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] customizing (per article) the "read more" links after excerpt

redbot wrote:

thank you maniqui but I don’t think it was necessary given that the “txp:body” tag doesn’t have attributes so doesn’t contains double quotes itself

TXP’s syntax doesn’t work as normal programming, scripting or makup language would. It’s about parsing, not escaping.

Values surrounded with double quotes are returned as non-parsed literal strings and only contents of single quotes are parsed. This is to reserve speed and backwards compatibility.

What comes to single quotes inside single quotes, escaping can be done using double single quotes, if parsing inside parsing is required:

<txp:foo bar='<txp:bar foo=''<txp:foobar />'' />' />

Let’s experiment. For example:

<txp:varialbe name="body" value="<txp:body />" />

Calling it returns: <txp:body /> (unparsed string). When:

<txp:varialbe name="body" value='<txp:body />' />

Returns: Lorem lipsum.

Offline

#10 2010-01-22 03:17:08

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: [howto] customizing (per article) the "read more" links after excerpt

Gocom wrote:

TXP’s syntax doesn’t work as normal programming, scripting or makup language would. It’s about parsing, not escaping.
Values surrounded with double quotes are returned as non-parsed literal strings and only contents of single quotes are parsed. This is to reserve speed and backwards compatibility.

Doh! Thank you for the clarification Jukka (and my excuses to Juliàn) . Actually I really assumed instinctively that parsing = escaping.

Offline

#11 2010-01-22 07:40:44

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] customizing (per article) the "read more" links after excerpt

redbot wrote:

Actually I really assumed instinctively that parsing = escaping.

When we take it out of context, it is. Scripting languages, like PHP, parse strings with similiar methods to speed up parsing :)

Offline

#12 2010-01-23 17:09:36

hans maulwurf
New Member
Registered: 2010-01-21
Posts: 4

Re: [howto] customizing (per article) the "read more" links after excerpt

Els wrote:

If you use just <txp:if_variable name="body"> you are testing for the existence of the variable, and even when its value is empty it always exists, because you set it with the <txp:variable name="body" /> tag. So you need to check if has a value or not.

That was the needed info.

Thanks to all of you it works very well now.

Textpattern rocks!

Offline

Board footer

Powered by FluxBB