Displaying “read more” next to the body’s last character.
Posted: 30 August 2006 12:21 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  301
Joined  06-28-2006

This is the code for the index :

<div class="entry-body">
      
{body_{x_lang}}
      {if extended_{x_lang}}
<span class="more" title="{x_more}">�</span>{/if}
</div>


Edit : the arrow character &#8594; was replaced by ? on the forum (above).

This is the code for the ful entry :

<div class="entry-body">
        
{body_{x_lang}}
        {extended_{x_lang}}
</div>

What I want is to display the read more arrow → at the right of the last character of the body, like this :

Body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body body. →

But I can’t find a way to do this since I don’t want to put that read more code into the body itself (because it’s not its place and it would show up on the full entry) and I want to use XHTML formating.

 Signature 
Profile
 
 
Posted: 31 August 2006 02:07 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  962
Joined  12-20-2002

I’m having the same problem with Textile-formatted entries. I think the way to go is to use PHP to cut off the last 3 characters of the body text, ie, “</p>” and display the truncated version. Then the “read more” can be made a part of the last paragraph. Looks like the PHP function to use is rtrim.

<?php
$text
= "{fieldname}";
$trimmed = rtrim($text, "</p>");
echo
$trimmed;
?>
<a href="">read more</a>

 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 31 August 2006 04:02 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  301
Joined  06-28-2006

Yes, I also saw a thread about pullquotes, but I don’t want PHP in my templates, isn’t there a plugin to do this ? Something like the opposite of backspace.

 Signature 
Profile
 
 
Posted: 31 August 2006 04:22 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  962
Joined  12-20-2002

Hmm. You’ve given me an idea. If you’re still in this bind by the time I finish it, it’ll solve your problem.

 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 31 August 2006 06:02 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  962
Joined  12-20-2002

I’ve copy-n-pasted together a quick plugin that’ll do this and much other string manipulation besides. Presenting PHPStringoo.

File Attachments
pi.phpstringoo.txt  (File Size: 5KB - Downloads: 129)
 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 31 August 2006 06:29 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  301
Joined  06-28-2006

I changed my code for the index to

<div class="entry-body">
      
{exp:phpstringoo function="rtrim" par1="</p>"}{body_{x_lang}}{/exp:phpstringoo}
      {if extended_{x_lang}}
<span class="more" title="{x_more}"></span>{/if}
      
</p>      
</
div>

but only p> is removed, leaving </
Am I missing something ?

 Signature 
Profile
 
 
Posted: 31 August 2006 06:32 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  962
Joined  12-20-2002

Not sure. Maybe there is some escape stuff happening through the EE template. Try backslashes? Or try something that counts the number of characters?

 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 31 August 2006 08:02 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  10-17-2002

A little alteration in your code should do what you want.

if extended is not empty

{if extended != ""}
<a href="{url_title_path=weblog/full}">(more)</a>
{/if}

Where (more) is your image.


and in your single entry page

{body}
{extended}

 Signature 

————————
Babs - Babineau.ca
Calgary | Alberta | Canada.

Profile
 
 
Posted: 31 August 2006 09:54 PM   [ Ignore ]   [ # 8 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15823
Joined  06-03-2002
Adam Khan - 31 August 2006 06:32 AM

Not sure. Maybe there is some escape stuff happening through the EE template. Try backslashes? Or try something that counts the number of characters?

Slashes are converted to entities in parameters.  There’s a constant defined, SLASH, that you can use to replace entity encoded slashes in parameters to their original state, following the pattern:

$str = str_replace(SLASH, '/', $str);

 Signature 
Profile
MSG
 
 
Posted: 01 September 2006 03:06 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
RankRankRank
Total Posts:  301
Joined  06-28-2006
MelodramaBabs - 31 August 2006 08:02 PM

A little alteration in your code should do what you want.

But how to position it where I want ?

 Signature 
Profile
 
 
Posted: 01 September 2006 05:05 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  10-17-2002
Sim - 01 September 2006 03:06 AM

But how to position it where I want ?

the first part goes in on your main index file (where you want people to see the extra arrow).

The 2nd part goes in your template for your single entry (permalink-type) page - where you do not want them to see the arrow.

These codes would go where ever it is in your template that you would want the {body} appear - same goes for {extended}

 Signature 

————————
Babs - Babineau.ca
Calgary | Alberta | Canada.

Profile
 
 
Posted: 01 September 2006 05:12 AM   [ Ignore ]   [ # 11 ]  
Research Assistant
RankRankRank
Total Posts:  301
Joined  06-28-2006

Are you sure that you have read my first post ?
It’s not an issue about adding the more thing it’s a more complex issue about displaying it in a very specific place.

 Signature 
Profile
 
 
Posted: 01 September 2006 03:15 PM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  10-17-2002

oops! sorry! then I’m not sure how to do what you want to do.

 Signature 

————————
Babs - Babineau.ca
Calgary | Alberta | Canada.

Profile
 
 
Posted: 05 September 2006 04:30 PM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  962
Joined  12-20-2002

If you’re still hellbent on not having PHP in your template, you can do it with an embedded template. Use the newer version of the plugin, PHPStringFun:

{embed="functions/remove-p-tag" trimmed="{exp:phpstringfun fun="trim"}{your_field}{/exp:phpstringfun}"}

Then in the “functions/remove-p-tag” template:

{exp:phpstringfun fun="substr" par1="0" par2="-4"}{embed:trimmed}{/exp:phpstringfun}

Would guess that works.

 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64878 Total Logged-in Users: 65
Total Topics: 81804 Total Anonymous Users: 41
Total Replies: 439753 Total Guests: 299
Total Posts: 521557    
Members ( View Memberlist )
Newest Members:  pticketdxrsmdanbilly8hrkiliwysso50kexpressoKlaasdarrenstylestravelerjcaton