开发者

What more I need to implement a "read more" feature

开发者 https://www.devze.com 2023-02-25 08:49 出处:网络
I want to implement a \"read more\" feature when I\'m displaying content. I want to cut off the text either at 6 lines or by number of words (but prefer by lines, unless you have different advice).

I want to implement a "read more" feature when I'm displaying content. I want to cut off the text either at 6 lines or by number of words (but prefer by lines, unless you have different advice).

I'm guessing I will have to use javascript for this and开发者_如何学JAVA calculate the text cutoff somehow. But I'm not quite sure what I should be doing, and if there's any calculation or other steps to do on the php end. Can someone give me some advice? Are there jquery plugins that could help with this?


You can use wordwrap with substr function of php


I've used this: Expander-Jquery-Plugin. And it's pretty cool :)

I hope this helps.


Say your content exists in a file, then you need to read 200 characters with it using php, then go ahead and read until you find a dot so that you know you have read until the end of the sentence. Then your "Read More" read can point to a page for example yourpage.php?fullcontent=yes and when the full content argument is given you read all the file.


You can do this in PHP, make two variables and truncate the "teaser" text variable to desired length

$teaser =substr($long_text, 0, 250); //250 chars

So, you have two variables, $teaser and $long_text. Use them as you like. You can use javascript to show/hide it Or if you decide to use a link (to a whole article page). You can altogether ignore the $long_text.

0

精彩评论

暂无评论...
验证码 换一张
取 消