/ Published in: PHP
I wrote this really quick and dirty script to paginate a very large chunk of text. A client site was setup with the understanding their about page would consist of 5-6 paragraphs but their biography ended up being 60 paragraphs. At the end of the day instead of breaking segments out into separate pages as stored in the database I kept it intact (including the way they edit it in the CMS) but this simple function paginates it only showing a certain number of paragraphs at a time.
Please email code -at- aristoworks.com if you need some clarification on how to use this.
Please email code -at- aristoworks.com if you need some clarification on how to use this.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function paraPag($data) { $chars = "<p> </p>"; // CHARACTERS TO REMOVE FROM LEFT AND RIGHT OF ORIGINAL TEXT $delimiter = "<br /><br />"; // COULD BE <BR><BR>, \n\r, OR ANYTHING THAT APPEARS BETWEEN YOUR PARAGRAPHS $num_page = 10; // THE NUMBER OF PARAGRAPHS YOU WANT DISPLAYED ON EACH PAGE $output = ''; // INITIATE THE VARIABLE // SET THE PAGE NUMBER $page = $_GET['page']; } else { $page = 1; } $start = ($page * $num_page) - $num_page; $end = ($page * $num_page) - 1; // PRINT THE PAGE CONTENTS for($i=$start; $i<=$end; $i++) { if($i< $count) { $output .= "<p>".$paragraphs[$i]."</p>\n"; } } // PRINT OUT THE PAGE NUMBERS for($i=1; $i<=$pages; $i++) { if($i == $page) { $class = "class=\"activePage\""; } else { $class = 'class="page"'; } $output .= "<a $class href=\"?page=$i\">$i</a> "; } return $output; }
URL: http://www.aristoworks.com