Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How do you display "read more" link on the page display with style "unformatted" and row style "fields".
Thanks,
Jhon
Comment | File | Size | Author |
---|---|---|---|
#45 | field_node_readmore-287812-45.patch | 2.7 KB | anrikun |
#43 | field_node_readmore-287812-43.patch | 2.79 KB | anrikun |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedPage 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.
Comment #2
wuf31 CreditAttribution: wuf31 commentedThanks 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.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedAhh. 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.
Comment #4
wuf31 CreditAttribution: wuf31 commentedWell..
I guess that would just have to do for now.
Thanks
Comment #5
David Lesieur CreditAttribution: David Lesieur commentedActually, would it make sense to request a "read more" link that behaves like core's?
Comment #6
David Lesieur CreditAttribution: David Lesieur commentedAh, actually, it seems to be there already.
Comment #7
wuf31 CreditAttribution: wuf31 commented@ David
Sorry, where? I don't seem to notice.
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedYou can always just use the 'link to node' field.
Comment #9
cpelham CreditAttribution: cpelham commentedHow 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.
Comment #10
merlinofchaos CreditAttribution: merlinofchaos commentedThat'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.
Comment #11
kenorb CreditAttribution: kenorb commentedYou can try use this: http://drupal.org/project/ed_readmore with #198026: Several fixes to "read more" link patch.
Comment #12
pastk CreditAttribution: pastk commentedWhat 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?
Comment #13
goye2cz CreditAttribution: goye2cz commentedI'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...
Comment #14
Doomd CreditAttribution: Doomd commentedPerhaps 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...
Comment #15
Doomd CreditAttribution: Doomd commentedSo...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:
Viola! An inline "Read More" link!
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedSounds fixed to me.
Comment #17
palamida CreditAttribution: palamida commentedI 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
Comment #19
imclean CreditAttribution: imclean commentedI 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):
3. In the "Value" field enter the following PHP code (with your field names):
4. Save the view and add a couple of classes to your css (inline styles are stripped from filtered input):
The above works for me. Adjust the PHP code to suit your needs.
Comment #20
drecute CreditAttribution: drecute commentedIn addition to the code given by @imclean, I found the following useful;
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
with
Comment #21
g.rogg CreditAttribution: g.rogg commentedThanks 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:
Comment #22
Jokes CreditAttribution: Jokes commentedThanx 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...
Comment #23
palmaross CreditAttribution: palmaross commentedIn 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!!
Comment #24
momper CreditAttribution: momper commentedi'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
Comment #25
momper CreditAttribution: momper commentedComment #26
NickTech CreditAttribution: NickTech commentedSubscribing. Would be nice to see teasers work inside field views the way they function on nodes.
Comment #27
Shane Birley CreditAttribution: Shane Birley commentedI 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!
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedHi,
I'm interested in this too.. Was a new ticket created for this? If yes, may we have a link?
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous commentedI could not find a new ticket, so I created one: http://drupal.org/node/1015632
Comment #30
anruetherHi 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?
Comment #31
anruethersorry, didn't want to change the thread titile...
Comment #32
michaeldaly352 CreditAttribution: michaeldaly352 commentedI 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:
So I just defined these classes in a new css file in my theme directory, flushed cache and voila.
MD
Comment #33
beifler CreditAttribution: beifler commentedFor 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!
Comment #34
Summit CreditAttribution: Summit commentedHi,
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
Comment #35
dqdINFO: But please beware that the solutions here are not translatable. Therefore you need to use view customfield with t('readmore')
Comment #36
BlindWolf8 CreditAttribution: BlindWolf8 commentedSubscribing.
Comment #37
sc0tt30 CreditAttribution: sc0tt30 commentedHate 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 alternativevisibility: hidden;
which also works, but leaves the space where the hidden text would appear, whereasdisplay: 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> </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:
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?
Comment #38
nick_t CreditAttribution: nick_t commentedSubscribing.
Comment #39
japo32 CreditAttribution: japo32 commentedYep this fixed it for me. Thanks!
Comment #40
peacekaat CreditAttribution: peacekaat commentedHere is another solution that does not require adjustment to the css. This could also be used with custom sprite image links.
Using customfield:
>^..^<
Comment #41
knalstaaf CreditAttribution: knalstaaf commentedIt displays the read more link in my Views preview, but not on the page itself...
Comment #42
knalstaaf CreditAttribution: knalstaaf commentedComment #43
anrikun CreditAttribution: anrikun commentedThe 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.
Comment #44
dawehnerIn general i'm wondering about the difference between this and a node:title with rewrite of the text.
There is no need for that, because readmore_node didn't existed before.
Can you explain this, i never saw that before.
Comment #45
anrikun CreditAttribution: anrikun commentedAs written at #43, the difference is that patch here provides the same accessible link Core displays on node teasers.
See
node_build_content()
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.
Comment #46
Maedi CreditAttribution: Maedi commentedViews 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
Comment #47
anrikun CreditAttribution: anrikun commented#45: field_node_readmore-287812-45.patch queued for re-testing.
Comment #48
kenorb CreditAttribution: kenorb commented