Currently, there is a way to trim text by enabling "Trim this field to a maximum length" in the field options when adding a field and then to add an ellepsis "..." after the text. I'm requesting to have a feature to use add a read more link instead of an ellipsis. You can integrate with ed_readmore.module or have your own thing.

Comments

dawehner’s picture

Component: Views Data » node data
Category: feature » support
Status: Active » Fixed

You could create a read more link via the ui, with rewrite output and display as link.
Then you can display the created field inline. Thats all you need.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jeffschuler’s picture

Status: Postponed » Active

dereine, one could also create an ellipsis ("...") via a field in the Views UI, however, it was thought practical to include it as part of the trimming functionality.

I agree with radj that customizing this post-trim-text ( "read more", "...", etc.,) -- and the option to link that text to the original post -- would make the trimming a lot more functional.

A couple downsides I see to dereine's proposed solution are:

  1. the link is always printed, rather than only so when the post has been trimmed,
  2. making the fields inline doesn't really work for text in <p>'s, (like most node body content,) as <p> within <span> would be counter to W3C HTML guidelines and break validation. The trimming functionality nicely injects the ellipsis into the trimmed markup... as we'd like it to do for this proposed editable text.
buckley’s picture

Category: support » feature
Status: Closed (fixed) » Active

yup, specifying a "read more" link after the ellipsis is the way to go. I need this and have had the same remark a couple of times on irc.

As jeffschuler points out this woul print "read more" only when the text is actually trimmed.
dereine solution is the one I am using now but it also suffers from the fact that you cannot place it after the "..." because there is a closing

tag after it.

buckley’s picture

Warning !! I hacked the core

If you are sensitive don't read more. Every time someone hacks the core a pussycat gets killed :(

If you edit the file

views_handler_field.inc

and search for the following line :
if (!empty($this->options['alter']['ellipsis'])) {

You can replace it with

if (!empty($this->options['alter']['ellipsis'])) {
//hack :(
$value .= '... ' ;
}

That's it ... the readmoreplaceholder won't be displayed if not used but you can replace it in your template file with the real link that you get from a views field (link not node).

Some day when I know drupal better and this gigantic views module I will come back and write a patch...

esmerel’s picture

Status: Active » Postponed
rwt’s picture

Status: Active » Postponed

Hello,

This is a basic solution I've come up with that does not require any code. I've you need something more advanced, you may always install the "Views Custom Field" module.

Using CCK, I created a new text field to my content_type : "field_summary".

In Views, I include Node >Path, my custom field Content > Summary and the body Node > Body

I exluded Path from display… obviously.

I you wish, you may trim your custom field's maximum length, just remember to remove the ellipsis.

Then for the body node, I rewrote my output as such:

<a href="[path]" class="read-more">Read More &#8230;</a>

&#8230; corresponds to the ellipsis html unicode.

And checked "Hide if empty".

Voilà !

The advantage of that solution is that it's quickly done (if you haven't already filled in your content) and it gives two fields for the "writer" to use which is more straightforward.

With views_custom_fields you could check for the lenght, and then trim the text and add the Read more link to the '[path]' node.

AdrianB’s picture

I'm with jeffschuler on this one.

I think dereine is missing what's important here: To only display the "Read more" link when there's more to read. I don't see how the proposed solution by dereine takes care of that. And dereine's logic there should be an ellipsis option either, but there is.

Views Custom Field is overkill in this case since it's almost there already, the logic of when the ellipsis is shown should be reusable.

tim.plunkett’s picture

Status: Postponed » Needs work
StatusFileSize
new952 bytes

In D6, node.module checks before printing the "Read more" links. ($node->readmore = $node->teaser != $node->body;).

I think what is being suggested is similar. A way to only print the "Read more" links when the trimmed result is shorter than the untrimmed data.

This doesn't work at all, but its a push in the right direction.

dawehner’s picture

Additional this will break any instance of ellipsis

LEternity’s picture

subscribe

jasher’s picture

I'd also like to see a more straightforward, "post-trim text" option. Perhaps with something like "link this text to this field's node".

I struggle to think of cases where one would want post-trim text that said something *other* than an equivalent of "Read more" ("read the rest of this article", "Cont.", etc.). But it would probably be nice if the option was there from the start.

(Similarly, I can't think of a case where one wouldn't want "read more" to be a link to the whole node, but giving the option for other links could overcomplicate things.)

njathan’s picture

Can this be done using PHP code in the Views Customfield module rather than hacking the Views module itself?

summit’s picture

Subscribing, needing a link to the complete node using ellipsis ("...").
Because when I use the field Node: Link as ..read more.., the link is always shown, also when the node-body is too small for it.
Thanks for going into this!

greetings, Martijn

brynbellomy’s picture

Status: Needs work » Needs review
StatusFileSize
new3.17 KB

This should do the trick. This gives a textbox (which accepts replacement tokens), the contents of which is only appended to the field if the trimmed text does not match the original text.

brynbellomy’s picture

Title: "read more" link option instead of ellipsis for trimmed text » New field option: add user-specified suffix (containing tokens) to field only when field is trimmed

Changing title due to expanded scope of this feature.

jthomasbailey’s picture

Works great, exactly what I needed. Just too bad the closing

makes it appear on another line.

merlinofchaos’s picture

Status: Needs review » Needs work

Hmm. Why is this separate from the ellipsis? Couldn't we retool the ellipsis checkbox to turn this on, and then have the ellipsis be the default text to add?

leoduquette’s picture

If I'm reading this properly, I think this is what was needed as the original response.

Under "VIEWS>>Fields>>Node: Link (Provide a simple link to the node.)
You can add whatever text you want there and it will link to it's node.

And of course Turn ellipsis off

rv0’s picture

subscribe

rv0’s picture

I solved this now partially with the solution in #7
but instead of using views custom field, i just loaded the field i needed twice:

first instance: trim to length, exclude from display
second instance: rewrite output as [firstinstance_name] Read more

that way no theming change was needed as I'm still using the original field.

LiloLilo’s picture

I can't figure out how to add a Read more link to trimmed text. Can anybody explain me again? Thanks

mustanggb’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)