(Background: #287812: Provide a "Content: Read more link" field, #1015632: Option to add links section to end of teaser fields e.g. "read more")

Suppose you want a list of teasers, each with a "read more" link to the full node. This "read more" link should only appear if there actually is more to read i.e. if the teaser is shorter than the body text. This is easy: choose row style nodes ("content"), view mode teaser, check display links and you're done.

Suppose, however, you need row style fields. Because e.g. you need to display specific fields, or because you need a teaser that is shorter than the default teaser length. Displaying a "read more" link only if there actually is more to read is not possible with just views. A work-around exists (see first issue referenced above), involving

  1. several extra non-displayed fields
  2. a contributed module to add PHP code
  3. a piece of CSS

This seems way to complicated. Especially since views already knows there is more to read: just check "Trim this field to a maximum length", and an option will appear to add an ellipsis if a field was trimmed.

Would it be possible to make this easier? By adding an optional "read more" link to the ellipsis option (see mockup)? Or a more generic solution, by replacing the ellipsis with a custom text/token input field?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dqd’s picture

yesss! ... and it should also solve the problem of making "readmore" translatable. Using Node:Link with custom text is a problem for i18n sites because t('readmore') does not work here

dawehner’s picture

Or a more generic solution, by replacing the ellipsis with a custom text/token input field?

This seems to be the most generic implementation and conceptual looks fine for me.

mjcarter’s picture

Yes, this is a seriously missing feature

Edit: Thought I had an idea of a solution but sods law...

Summit’s picture

Hi, still very interested in a solution for this please?
greetings, Martijn

RachelIsland’s picture

I would loooove a solution too...

dawehner’s picture

Status: Active » Needs review
FileSize
3.36 KB

Here is a small patch which allows to use tokens both for the more link text and the more link path

Hydra’s picture

Status: Needs review » Needs work

Nice work! This is a well needed feature. I think it should be possible to use the node: path field as a token, right now all I could get woring was the nid field as a usable token/path.
It would also be nice, if the read more link would reference automaticly to its content, if possible.

dawehner’s picture

Status: Needs work » Needs review
FileSize
3.99 KB

Two changes to the patch.

* Add a help description
* Take sure that relative links like /foo/bar works as well. Basically everything which is runned through url().

dawehner’s picture

FileSize
4.31 KB

Now the replacement patterns are shown above it.

Hydra’s picture

Status: Needs review » Needs work

Works for me! You should adjust the help message to "above" at the end when the eplacementpatterns are shown above and not below.

+ '#description' => t('The path which is used for the more link. You may enter data from this view as per the "Replacement patterns" above.'),

dawehner’s picture

Status: Needs work » Needs review
FileSize
4.31 KB

Just a small update

Hydra’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine :)

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks for all the testing.

Would be definitive a worth feature for 6.x-3.x as well.

traveller’s picture

What is the replacement token for the node's link path? Such token is not listed in the options.
Without setting it, the 'read more'-URL is set to the root of the website.

ntg’s picture

You can add a "Node: Path" field, exclude it from display and then use the "[path]" as the path of the "More..." link.

chunty’s picture

Could someone that knows how extend this patch allow it to accept HTML entities like » in the read more text. I'd do it myself but I'm not quite up to speed enough yet.

Much appreciated
Chris

traveller’s picture

There is no direct solution, but using 7.x-3.x Views I used ntg's #15 suggestion: add new field "node path", exclude it from display, then set [path] as the path for the "read more" body field.

chunty’s picture

Having played with this a little more without wanting to disrespect or dismiss the work that has gone into this for D6 (which I'm using) I've come the conclusion that actually the best solution is simply to use a custom markup field.....why? because:

  1. First and for most what I really wanted was that the "read more" text became part of the paragraph when its trimmed in the same way the "..." does however that's not the case which means it always appears on a new line and NOT at the end of the trimmed paragraph and on that basis I can already do this with a custom markup field
  2. The current patches do not let you include thing like » in your text which a custom markup field does
  3. In any case you need to define a field for the path and hide it.

Hope that helps someone but even so thanks to the folks that have put the time into building this and I'm sure it helped you.

C

vchen’s picture

Version: 6.x-3.x-dev » 7.x-3.3

Using views 7.x-3.3

Confirming that #15 solution works.

Problem: read more links using [title] pattern did not link to the any page. Using [path] pattern (after adding the Content:Path field, and then exclude from display) did the trick. Read more link now links to the content.

Hydra’s picture

Version: 7.x-3.3 » 6.x-3.x-dev

Of Course #15 is working. You can use any token as path. If you are using a token wich not leads you to the destination you wish to, it's not working. It would be nice if it would automaticly reference to the content, but this is an other issue. Right now it's working perfectly well and it's ready to be ported.

shiroitatsu’s picture

#15 doesn't work if one happens to be working in a language that has special characters that [path] messes up for some reason and the path alias is broken. I use [nid] instead, linked to original content and rewritten to be "read more…" or what ever is needed. Quite complicated and not very intuitive for the purpose.

Chris Matthews’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (outdated)

The Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue