Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2006-11-13 09:11:11

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

Re: place a "read more link" inside the excerpt element?

Having trouble with an up to now working solution,
I want to bring this back to discussion.

My question
How can I place the “read-more”-permlink within the last test-paragraph of an existing exzerpt?
(without having to place it manually!)

Perhaps I did miss something and this is possible by txp-on-board-tools. But I didn’t find anything. Any tipps?

So far I see the following scenario: In existing excerpts the end can have different code:
  • Sometimes ending simply with </p> (the normal case in txp 4.0.4)
  • When users write an empty line (double return) at the end, then there is a </p> followed by two paragraphbreaks
  • In older dataentries coming from txp 4.0.3 there is a </p> followed by two paragraphbreaks and a space
  • If there is an image in the excerpt the last tags may be different. In txp 4.0.4 it normally seems to be a </p>, but I think there may be other scenarios too.

At the moment I’m using the plugin “beginning”. But I only use the function to place a permlink within existing exzerpts. Maybe it would be better if there was an extra small plugin doing this – or much better an attribute in txp_excerpt, placing permlinks.

The plugin “beginning” simply strips an amount of characters from the end and replaces a </p>-Tag – this way running into problems.

So to place the read-more-permlink correctly we have to find out the right ending tag and placing the link just before.

This seems to be manageable by a simple code.
But how?

Offline

#14 2006-11-13 15:00:43

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

Re: place a "read more link" inside the excerpt element?

Does this post help you? It only requires that users put a txp tag in the excerpt.

Offline

#15 2006-11-13 15:15:50

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

Re: place a "read more link" inside the excerpt element?

Ah, thank you! For me it’s interesting and helping.

But my users barely read instructions (even my empathetic instructions – sigh) and follow the main steps writing an article, setting the right category …;
and I don’t want to bother them with too many additional tasks like typing/copying those tags.

And I think this is a task, the machine could and should do pretty easy.

What would help me (shame I didn’t learn php yet!):
The main question is: How can a php-code find and possibly eliminate the last </p>-tag in a string? (for this seems to be set in excerpts in most cases)
And possibly stop, if there is another text apart from spaces and paragraphs? (for special scenarios)

Then it would be easy adding the permlink and provide a closing </p>-Tag as the plugin “beginning” does it.

Offline

#16 2006-11-13 21:57:03

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

Re: place a "read more link" inside the excerpt element?

If you can be sure there won’t be any other html code in the excerpts except the <p> tags, you could probably use etz_striptags.

Offline

#17 2006-11-13 22:01:48

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

Re: place a "read more link" inside the excerpt element?

I fear I can’t be sure, for sometimes there will be images.
And of course br-Tags.
Will this strip all tags or just the beginning and ending p-Tags?
If the last, that would be just the matching code for my problem.

Offline

#18 2006-11-13 22:15:20

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

Re: place a "read more link" inside the excerpt element?

I’m afraid it strips all tags. But you could make a plugin request, I’m not a coder myself, but I don’t think it’s very hard to do with php.

Offline

#19 2006-11-13 23:17:58

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

Re: place a "read more link" inside the excerpt element?

@saccade
What I don’t really keep understanding, is, why you need the link inside the last p tags?
With the current tags und plugins, you can put the read more title text inside a custom field, and have it automaticlly appended as the last paragraph, after there already is generated by textile.
Then, as a fallback value, in case nothing was entered, it’ll be something like :
Read more of this …..

I couldn’t think of a regular expression, that would match the last paragraph of a document and then in php there are used different.

regards, marios

Last edited by marios (2006-11-13 23:21:49)


⌃ ⇧ < ⌃ ⇧ >

Offline

#20 2006-11-14 06:14:40

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

Re: place a "read more link" inside the excerpt element?

@marios

Let me describe why I want the link to be inside:
In my matters of content normally excerpts will be one or more paragraphs of text to give some view on the following and make it interesting to continue reading. This text mostly will be a truncated copy of the first sentences of the full body.
So the “read more” is semantically a part of the text and not a new paragraph.

Of course I could place it by CSS inline at the end of the text paragraph, but that seems to be not a good solution for me.

I have plain HTML without CSS in mind too. There it should look well ordered too:
So for accessibility (for example viewing without CSS on a mobile) I think it is better to have the plain “read more”-link inline at the end of the last paragraph of the excerpt.

It should look like this:

New image gallery
We’ve posted the images from last weekend. A bunch of fotographers didn’t stop working. There were taken more than 1000. You will find that … read more …

It should not look like this:

New image gallery
We’ve posted the images from last weekend. A bunch of fotographers didn’t stop working. There were taken more than 1000. You will find that …
read more …

In plain HTML a separated read-more-link also will be separated additionally by paragraph leading from the paragraph before (that doesn’t show here). Exactly that I don’t want.

The customfield solution also produces a separated paragraph.
But also I don’t want my users have to fiddle anything – it showed, that using a customfield is too complicated for them (sigh). It is not a problem of the title text.
It should work automatically.

Last edited by saccade (2006-11-14 06:19:29)

Offline

#21 2006-11-14 06:16:03

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

Re: place a "read more link" inside the excerpt element?

Just do:

Here is my excerpt. <txp:permlink>Read more of this amazing article!</txp:permlink>

Offline

#22 2006-11-14 06:31:36

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

Re: place a "read more link" inside the excerpt element?

@Mary

Thank you very much. That will work, if you are able to work with tags. I knew that solution.
But the users of my sites don’t. So I think it will not work in the wild (and I don’t want to have to review every article excerpt and correct or add the link).

It is hard enough to get them using the write forms, category and sections and article status correctly.
They will refuse to use correctly anything containing < and > and :.
They won’t close the Syntax, add spaces after : and so on.
And they will complain, if I add too many “And now do this”-paragraphs to the manual. ;)

And I want them to concentrate to their content, not to placing tags. So I want to have it as easy as possible for them.
To us it seems very easy to add this little snippet of code. But it isn’t for people who barely know what HTML is.
I look for a way to have it done automatically.

Last edited by saccade (2006-11-14 06:42:41)

Offline

#23 2006-11-14 13:53:02

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

Re: place a "read more link" inside the excerpt element?

So you create a plugin to try and do it for them; a carefully crafted preg_replace should do the job.

Offline

#24 2006-11-14 15:49:14

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: place a "read more link" inside the excerpt element?

If you’re scripty, you can probably just add a function attribute to rss_automatic_excerpts instead of trying to reinvent the wheel. Or alternately if you ask Rob really nicely, he may just add the function in the next release.

Offline

Board footer

Powered by FluxBB