If you’re developing website with PHP to list multiple article on home page. Then definitely you will need to display only few starting lines of each article content with “Read More…” link to display full article content in a page when click on “Read More…” link. It would be best approach to display “Read More” with each article because it will allow you to display more articles in a single page that will increase readability of page.
You may also like:
- Create Advance Pagination with PHP and MySQL
- DataTable Pagination using PHP & MySQL
- Create Bootstrap Table Pagination with jQuery
So here in this post, you will learn how to create “Read More…” link and clicking on it will display full content in a page.
Here is an example of creating read more link of content to display few line of content with “Read More…” and by clicking “Read More…” will display full content in page.
<?php $content = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam"; // your page id to display full content $page_id = 456; // your page file to display full content $link = "page.php"; // limit content character $limit = 100; // Called readMore() function to convert full content to read more link echo readMore($content,$link,"id",$page_id, $limit, $limit); ?>
The below code will display content with few lines with “Read More…” link.
This is a readMore() function to create read more link of a content.
<?php // Function to create read more link of a content with link to full page function readMore($content,$link,$var,$id, $limit) { $content = substr($content,0,$limit); $content = substr($content,0,strrpos($content,' ')); $content = $content." <a href='$link?$var=$id'>Read More...</a>"; return $content; } ?>
You may also like:
- Star Rating System with Ajax, PHP and MySQL
- Create Event Calendar with jQuery, PHP and MySQL
- Build Your Own CAPTCHA Script with PHP
- Convert Unix Timestamp To Readable Date Time in PHP
- Inventory Management System with Ajax, PHP & MySQL
- Create Live Editable Table with jQuery, PHP and MySQL
- Live Add Edit Delete datatables Records with Ajax, PHP and MySQL
- Stripe Payment Gateway Integration in PHP
- Export Data to Excel with PHP and MySQL
- Star Rating System with Ajax, PHP and MySQL
- Create Dynamic Bootstrap Tabs with PHP & MySQL
- How To Create Simple REST API in PHP
Here we have developed a complete read more script the help of above example code. You can see this script in action from below live demo link.
Thanks 🙂
You’re welcome!
Thanks, it’s working for me!
you’re welcome! thanks!