Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-11-19 23:36:37

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

sac_link_in_excerpt

Looking for a way to place the permlink within the last paragraph of an existing excerpt I ended up with the following attempt to create a Plugin:

Plugin: sac_link_in_excerpt 0.1.2
Code plaintext:
(updated with example in help)

It does only one thing: Place the permlink and return the excerpt. No auto-generation of excerpts.
(As I asked here , here and here it would be nice to have this effect in rss_auto_excerpt and in Beginning too)

I’m no skilled php-coder, I did only what I understand so far.

Thanks to the authors of Beginning and a function at php.net found here

Now I have questions for the experts:

  • Does the code seem reasonable and is it safe, correct and valid?
  • Is there a better way to do things?
  • Which credits should I place in the plugin? (I don’t know how to deal with that code adapted from php.net)

Thanks for any help!

PLUGIN HELP

Placing the Read-more-Link inside the last paragraph of an existing excerpt.

This Plugin will locate the last </p>-tag within an existing excerpt and place the article’s permlink right before it.

This effect is desired because of logic and accessibility: If you place a truncated part of text in your excerpt, it’s more logical if the “read more”-link follows after the last word of excerpt text, than if it starts in a new paragraph.
When it comes to design you can place and format the link wherever you want using css. If css is not active, the link sticks to the text it will “continue”.

There are a few attributes to tweak the way, the link is placed:

  • linktext = The linktext. Default = “Read more”
  • styleclass = class-attribute for the link. the link is enclosed with spans this attribute is applied to. Default = “morelink”
  • cfield = If you want to override the above defined linktext for an article you can use a customfield. Here you can specify which customfield to use. Default = “continue”. You can use fields of the article as well ($thisarticle-fields), e.g. “title” or “keywords”, “titleid”.
  • pretext = Characters/text that should precede the link but not be in the link itself. Default = “ “
  • endtag = Here you can define which tag’s last occurence should be taken for placement. Default = "</p>"

Example:
<txp:sac_link_in_excerpt pretext=" ... read the " linktext="full article" styleclass="contlink" />

How the Plugin works:

  1. The position of the last occurrance of the endtag is located
  2. The excerpt string up to the position is saved
  3. The excerpt string from the position to the end is saved
  4. The link will be placed between the two strings of 2. and 3.

If the excerpt is empty, the plugin will return the body of the article.
If there is no occurrance of the endtag found or the endtag defined as empty (default overridden), the plugin will return the excerpt and the link in an extra paragraph.

Last edited by saccade (2008-04-16 16:14:50)

Offline

#2 2006-11-21 08:42:15

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: sac_link_in_excerpt

Saccade, you finally made it. Congrats. I didn’t really understand the reasoning ,the first time this came up.
But yes you are right. The read more link should really be inside the last p tags.

Brilliant. I’ll let you know, if it works for me.

regards,

Last edited by marios (2006-11-21 08:42:32)


⌃ ⇧ < ⌃ ⇧ >

Offline

#3 2006-11-21 09:18:43

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: sac_link_in_excerpt

Seemed to work fine even on a modified install of TXP 4.04
I placed it once before and once after the body tag, just to see.
You might want to include, where exactly it can be used.

Only in debugging mode I get the following tag errors

In testing and live no Errors.

regards, marios

Last edited by marios (2006-11-21 22:37:20)


⌃ ⇧ < ⌃ ⇧ >

Offline

#4 2006-11-21 09:32:36

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sac_link_in_excerpt

Thank you for testing.
I’ll look after it, but now I’m out of my office. Hope to have time this afternoon.
best regards,
Michael

Offline

#5 2006-11-21 11:35:39

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sac_link_in_excerpt

What I figured out so far:
The error origins from the “check for custom field entry”.

EDIT 3 (there were some misleading erraneous thought by me, now corrected)

If there is no matching customfield, the error will appear.

To get rid of the error messages you can do one of the following:
  • Set up one of the (unused) customfields as “continue”.
  • Specify the atrribute cfield= with an existing customfield (that you want to use when applicable or which is alway empty). cfield="custom1" or cfield="custom2" will refer to the predefined customfields. Of course this only works if you didn’t rename or fill these customfields.
  • Modify the plugin and outcomment these lines as follow
    //Check for custom field entry.
    //if (trim($thisarticle[$cfield]) != '') {
    //$linktext = $thisarticle[$cfield];
    //}

Last edited by saccade (2006-11-22 16:12:56)

Offline

#6 2006-12-05 11:28:45

alexandra
Member
From: Cologne, Germany
Registered: 2004-04-02
Posts: 1,370

Re: sac_link_in_excerpt

Hi saccade,
thanks for this wonderful plugin! Very much appreciated :)

In debug mod i get the following errrors:

tag_error <txp:sac_link_in_excerpt pretext=" ... read the " linktext="full article" styleclass="contlink" /> -> Notice: Undefined index: continue on line 19

textpattern/lib/txplib_misc.php(512) : eval()'d code:19 sac_link_in_excerpt() textpattern/publish.php:958 sac_link_in_excerpt()

the Plugin though works in Live mod.

Anything i should change or keep an eye on?

Last edited by alexandra (2006-12-05 11:34:29)

Offline

#7 2006-12-05 11:56:01

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sac_link_in_excerpt

Hi alexandra,
thank you for the kind feedback :) I’m glad if this small piece helps.

this error occurs, when cfield is not defined or points to a nonexistent field.
I didn’t yet find a solution to avoid it (ehm – didn’t have enough time to search a solution :) ).

A workaround is the following:
define cfield and point it to a not used, empty customfield, e.g.
cfield=“custom2”

The errors then should vanish (at least I didn’t see any remaining problem).

And of course the other solutions of the post before work too, so maybe it is the most convenient way to define a customfield as “continue” and use it from time to time or not at all.

The plugin sets cfield to a default “continue” if it is not defined. If this field is empty, the specified linktext will be used. If it contains something this will be used.
If it is not there, then the errors appear.

Last edited by saccade (2006-12-05 12:04:49)

Offline

#8 2006-12-05 12:03:16

alexandra
Member
From: Cologne, Germany
Registered: 2004-04-02
Posts: 1,370

Re: sac_link_in_excerpt

Would it cause any problems if i just leave it as it is? Trouble is, i tend to forget about such extra solutions for a plugin on the long run :)

Offline

#9 2006-12-05 12:11:36

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sac_link_in_excerpt

Unfortunately I’m not (yet, but I’d like to learn more) an expert in coding nor security or performance.
And I don’t know, if there is an output of errors, when not in debug mode.
Normally I would say it is better to avoid any messages.
But you have to ask someone with more knowledge.
(Though: From my view it will not cause problems. It hasn’t as far as I can see before.)

I will try to find a solution, so you don’t need any workaround (but you have to wait minimum until tomorrow).

If you don’t need any exception from the linktext, then it would be the very best, to outcomment the lines I showed above. With an update of the plugin later everything would be corrected automatically and the template/form-codes will be clear from the beginning.

Last edited by saccade (2006-12-05 12:12:45)

Offline

#10 2006-12-05 12:43:08

alexandra
Member
From: Cologne, Germany
Registered: 2004-04-02
Posts: 1,370

Re: sac_link_in_excerpt

Hi saccade, i work on a re-design for TXP Mag and am not in a hurry at all. Everything is on a test install. Right now i will wait for an update of the plugin. If you like to ask someother coder, ask Bastian from samisdat.org. He speaks german too.
Thanks for your fast reply :)

Offline

#11 2006-12-05 13:19:23

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sac_link_in_excerpt

I made a fast attempt to fix.

Here’s the result: Plugin: sac_link_in_excerpt 0.1.2
Code plaintext:

I wait for some reports whether it is ok or if tere are some bugs/errors, before I post it to the beginning of this thread.

Last edited by saccade (2008-04-16 16:18:01)

Offline

#12 2006-12-05 13:27:10

alexandra
Member
From: Cologne, Germany
Registered: 2004-04-02
Posts: 1,370

Re: sac_link_in_excerpt

Saccade, no more errors in debug mod :) now! I will test the plugin a bit mor tonight and report back then. Thanks for quick fix!

Offline

Board footer

Powered by FluxBB