How do you display "read more" link on the page display with style "unformatted" and row style "fields".

Thanks,

Jhon

Files: 
CommentFileSizeAuthor
#45 field_node_readmore-287812-45.patch2.7 KBanrikun
PASSED: [[SimpleTest]]: [MySQL] 1,652 pass(es).
[ View ]
#43 field_node_readmore-287812-43.patch2.79 KBanrikun
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

Comments

Status:Active» Closed (works as designed)

Page displays do not support the 'read more' link, since they consider themselves the authoritative place for that content; i.e, they are the destination for read more. A read more link would just loop back to itself. Other display types support read more links.

Status:Closed (works as designed)» Active

Thanks for the swift reply.

By the "read more" link, i don't mean the one that's at the bottom of a block display,
but rather the one user gets when only node teaser are displayed.

Ahh. That only comes as part of the node teaser. However, I believe you can do the 'node: view link' field and put in 'read more' in the text. It won't, however, take things like teaser/body difference into account, so it won't be quite the same as the real read more link.

Status:Active» Closed (fixed)

Well..
I guess that would just have to do for now.

Thanks

Version:6.x-2.0-rc1» 6.x-2.x-dev
Category:support» feature
Status:Closed (fixed)» Active

Actually, would it make sense to request a "read more" link that behaves like core's?

Status:Active» Closed (fixed)

Ah, actually, it seems to be there already.

Status:Closed (fixed)» Active

@ David
Sorry, where? I don't seem to notice.

Status:Active» Closed (fixed)

You can always just use the 'link to node' field.

Status:Closed (fixed)» Active

How would one theme the 'link to node' field inline with the teaser, as you suggest doing on angrydonuts? I have tried checking it off under the field formatting. I have tried adding display: inline to the field's css. but there seems to be an extra span tag or something so that it won't jump up there.

That's tough, because the teasier is inside p and div tags, so you would have to actually modify it in nodeapi to insert the link. Views can't really do that since it's already got that chunk of output.

What if the teasers are optional? I.e. some nodes may have teasers (if the user inserted a "<--break-->") and some are not.
The "read more" link should be rendered only in the first case. Unfortunately, the 'link to node' field can't provide this flexibility (the link always shows up).

Any ideas how to do it without hacking or themeing views output?

I've had an issue getting the "more" link to show up as well. I'm using views to create a block display which shows the title, teaser, and hopefully the more link. Setting the more link to "yes" doesn't seem to do anything. I've added a field which links to the node which gets the job done but not completely. It only shows up with what I put in for the text. I have a multilingual site so this isn't completely effective. Have I missed something?

***EDIT**
I realize that I misunderstood the purpose of the "more" link. I now know it is not a "read more" link but a link to show more nodes. I still would like to know about "read more" and ways of implementing that for a multilingual site. Sorry if I've gone off topic a bit...

Perhaps there is a way to "Rewrite the output of this field" to include a "Read More >" Link after the body (or teaser). I don't know how to do it myself...but I would LOVE it if someone posted a solution...

So...I just wanted to follow up with a SOLUTION.

After doing a bit of research, I finally found a tutorial with an excellent explanation of how to use "Rewrite the output of this field": http://pras.net.np/blogs/styling-views-using-output-rewrite

What I did is make a view field for (Node: Teaser), then I "Excluded it from display". I also made sure that I checked the box for "Strip HTML Tags" because it will screw up with the output.

Then I created another field "Node: NID". Also exlcude this field from display.

Then I resorted the order of the fields, making sure that the "Node: NID" field and the "Node: Teaser" field were ABOVE the "Node: Link" field (which I will create below...). We create this field because we need to use the field's Node ID as a token for the link we will create below

I then I created a field for "Node: Link" (which as mentioned, must be below the "Node: Teaser" field). Then I checked the "Rewrite the Output of this Field" box...

Here's what I put in that box:

[teaser] <a href='node/[nid]'>Read More</a>

Viola! An inline "Read More" link!

Status:Active» Fixed

Sounds fixed to me.

I use pathauto so node/[nid] was a partial solution for me... I changed the "doubledoh" #15 solution from:

[teaser] <a href='node/[nid]'>Read More</a>

to

[teaser][view_node]

( the view_node is the token for the node link itself )
and finaly inserted the "text to display": "Read more..."
The Node:Nid field is no longer needed, the hidden Node:Teaser yes

The "Read more" is present even if there is nothing else to read... but until a much cleaver solution i'm fine with that

Status:Fixed» Closed (fixed)

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

I had a similar need, but instead of a teaser I used a custom "overview" field and the "body" field was used for further info (reading more), if any. You could probably do something similar with the teaser. It was quite important to the client that the "Read More" link was hidden when there was nothing else to read.

This is the module I used: http://drupal.org/project/views_customfield

In the Edit View screen:

1. Create a Node: link field, text "Read More", and exclude it from view.

2. Add a new field customfield -> PHP Code. Remove label (if required) and select "Rewrite the output of this field" then enter in the following (or your equivalent fields):

<div class="[phpcode]">[view_node]</div>

3. In the "Value" field enter the following PHP code (with your field names):

<?php
print (strlen($data->node_revisions_body) > 0) ? 'inline' : 'hidden';
?>

4. Save the view and add a couple of classes to your css (inline styles are stripped from filtered input):

.inline {
  display: inline;
}
.hidden {
  display: hidden;
}

The above works for me. Adjust the PHP code to suit your needs.

In addition to the code given by @imclean, I found the following useful;

<?php
print (strlen($data->node_revisions_body) % strlen($data->node_revisions_teaser )== 0) ? 'hidden' : 'inline';
?>

What the above code means is that if the node:body content divided by node:teaser content returns a no remainder, hide the read more link else display it.

for the css:
replace

.hidden {
  display: hidden;
}

with

.hidden {
  visibility: hidden;
}

Thanks to imclean and drecute, it works for me too.
I had to add node: body field and excluded it from view, before, otherwise $data->node_revisions_body was not available.
In the "Value" field of customfield -> PHP Code, I entered this code:

<?php
print (strlen($data->node_revisions_body) > strlen($data->node_revisions_teaser) ? 'inline': 'hidden');
?>

Thanx for the solution you mentioned in #15, doubledoh.

Now: is there a way to adjust the look of the inline read more link? I want to downsize it a little, perhaps give it another color...

In case of teaser + body I entered:

[teaser]<span class="[phpcode]"> [view_node]</span>

So now "more" link is really inline...

And my fields set:

Node: Link (excluded from view)
Node: Body Body (excluded from view)
Node: Teaser Teaser (excluded from view)
Customfield: PHP Code
...

Works fine!!

Status:Closed (fixed)» Active

i'm sorry - the logic should be inside views ... since 2 years workarounds ... i reopened: it makes sense - it's basic usability for the user + this is definitly not fixed ...

thanks momper

Title:Read More Link ?Optional Read More Link?

Subscribing. Would be nice to see teasers work inside field views the way they function on nodes.

Status:Active» Closed (fixed)

I disagree with this being something to "fix". @momper, this is not a bug, this is how the current feature set functions (re: there isn't anything to fix). I would partner up with @nperonti with a new feature request.

@nperonti, could you do me a favour and open a new feature request for this ticket? This ticket is very old and I would prefer to see a new one since re-opening this over and over again makes any helpful developers unhappy and it confuses people as to what the real request is.

Thanks!

Hi,

I'm interested in this too.. Was a new ticket created for this? If yes, may we have a link?

I could not find a new ticket, so I created one: http://drupal.org/node/1015632

Title:Optional Read More Link?Optional Read More Link? - d7

Hi everybody, what about d7? I didn't get one of these solutions work. What palamida in #17 did was close, but then the whole teaser is marked as a link. And that's what I don't want?

any ideas?

Title:Optional Read More Link? - d7Optional Read More Link?

sorry, didn't want to change the thread titile...

I spent a lot of time trying to get imclean's post working (#19). I think the problem was with the '.inline' class...it needed further definition.

I found you can just enter the title, eg [view_node], in the 'redirect output to' box, without the code, and forget about the customcode module entirely. That box will let you do some styling, eg
<h3>[body]<h3>, that does not involve css. However, that was not enough.

I deleted the customcode module and things started to work again.

If you have installed the 'advanced help' module, the relevant advanced help for Views will tell you how to override css. It talks about copying views theme file to your default theme directory, renaming it then customising it. I got a bit lost with this, as I don't really know php. You should be able to access it,when logged in, from your site via the menu or directly from the address bar:
http://www.yoursite.com/help/views/theme-css

So instead I evaluated the source code of the page and found the css class coding for the view fields I wanted in question:

<div class="views-field-title">
<div class="views-field-created">
<div class="views-field-body">

So I just defined these classes in a new css file in my theme directory, flushed cache and voila.

MD

For the people landing on this page looking for a solution, what worked well for me was using a token method merlinofchaos mentioned in another thread. - In the view add the following fields:

Node: Link => Check "Exclude from Display" and under "Text to Display" put in something like "Read More" (if blank the link text will be "view")
Node: Teaser => Check "Exclude from Display" and "Strip HTML Tags"
Global: Custom text => Remove Label, and in the "Text" field add: [teaser] [view_node]

Voila!

Hi,

My solution was the same as #23. My ahah came from the fact that all other fields are excluded from display, but because of setting them as view fields, they become available for the views customfield field, and then can be manipulated as you like!
greetings, Martijn

INFO: But please beware that the solutions here are not translatable. Therefore you need to use view customfield with t('readmore')

Subscribing.

Hate to add to a closed issue, but many roads point here and I have some comments about some of the suggested fixes.

#19 proposes a nice fix using custom PHP fields and separate overview (i.e. teaser) and body fields.

I think the CSS in step 4 of #19 for .hidden should use display: none; #20 suggests an alternative visibility: hidden; which also works, but leaves the space where the hidden text would appear, whereas display: none; doesn't. 'Hidden' isn't one of the options for display in CSS.

#21 extends the php code from #19 so that is works with a standard teaser that is just the first part of the body. But some of my articles use the teaser break comment, and the <!--break--> tag appears in the body (but not the teaser) making them always unequal. Worse, my editor adds an empty paragraph <p>&nbsp;</p> after the break, so even if I filtered out the break, the body would still be longer.

To account for both situations, I added another test to the php code:

<?php
print (strlen($data->node_revisions_body) == strlen($data->node_revisions_teaser) || strlen($data->node_revisions_body) - strpos($data->node_revisions_body, '<!--break-->') <= 29 ? 'hidden' : 'inline');
?>

The number 29 is somewhat arbitrary, but accounts for the break tag, the closing paragraph tag that surrounds it, and the empty paragraph after it. I figure that no legitimately longer article would have fewer than 30 characters after the break.

That still leaves the inline problem discussed elsewhere (the opening paragraph tag before the break tag is in the teaser, and results in (at least for some browsers) a final blank paragraph, so inline doesn't do what you expect -- see http://drupal.org/node/573878 for more).

And just one further comment, since this is a feature request thread--it seems to me I've spent way too long on getting this to work, when it's something that I would expect 'out of the box.' After all, doesn't teaser imply a "read more" link, almost by definition?

Subscribing.

Yep this fixed it for me. Thanks!

Here is another solution that does not require adjustment to the css. This could also be used with custom sprite image links.

Using customfield:

<?php
$path
= 'node/' . $data->nid;
if (
strlen($data->node_revisions_body) > strlen($data->node_revisions_teaser)) {
print
'<a href="/' . drupal_get_path_alias($path) . '">Read more</a>'; }
?>

>^..^<

Version:6.x-2.x-dev» 7.x-3.x-dev
Status:Closed (fixed)» Active

It displays the read more link in my Views preview, but not on the page itself...

Version:7.x-3.x-dev» 6.x-2.x-dev
Status:Active» Closed (fixed)

Title:Optional Read More Link? Provide a "Content: Read more link" field
Version:6.x-2.x-dev» 7.x-3.x-dev
Component:page displays» Code
Status:Closed (fixed)» Needs review
StatusFileSize
new2.79 KB
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

The attached patch provides a *real* Content: Read more link field.
That is, the exact same accessible link as the one Core displays with node teasers.

Do not forget to clear your Drupal caches after applying the patch.

Status:Needs review» Needs work

In general i'm wondering about the difference between this and a node:title with rewrite of the text.

+++ b/modules/node.views.incundefined
@@ -262,6 +262,15 @@ function node_views_data() {
+  $data['node']['readmore_node']['moved to'] = array('views_entity_node', 'readmore_node');

There is no need for that, because readmore_node didn't existed before.

+++ b/modules/node/views_handler_field_node_readmore.incundefined
@@ -0,0 +1,42 @@
+      $this->options['alter']['rel'] = 'tag';

Can you explain this, i never saw that before.

Status:Needs work» Needs review
StatusFileSize
new2.7 KB
PASSED: [[SimpleTest]]: [MySQL] 1,652 pass(es).
[ View ]

As written at #43, the difference is that patch here provides the same accessible link Core displays on node teasers.
See node_build_content()

<?php
 
if ($view_mode == 'teaser') {
   
$node_title_stripped = strip_tags($node->title);
   
$links['node-readmore'] = array(
     
'title' => t('Read more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped)),
     
'href' => 'node/' . $node->nid,
     
'html' => TRUE,
     
'attributes' => array('rel' => 'tag', 'title' => $node_title_stripped),
    );
  }
?>

Before writing this patch, I had tried to reproduce this behaviour using node:title with rewrite but it didn't seem possible.
About attribute rel="tag", I have simply reproduced it from code above.

I'm attaching an updated patch with unnecessary 'moved to' being removed.

Views now has a 'read more' option in the settings, though I still find this module more useful as the link is inline with the text:
http://drupal.org/project/read_more

#45: field_node_readmore-287812-45.patch queued for re-testing.