分页段落-每页显示一定数量的段落
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分页段落-每页显示一定数量的段落相关的知识,希望对你有一定的参考价值。
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.
function paraPag($data) { $chars = "<p> </p>"; // CHARACTERS TO REMOVE FROM LEFT AND RIGHT OF ORIGINAL TEXT $delimiter = "<br /><br />"; // COULD BE <BR><BR>, , 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> "; } } // 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; }
以上是关于分页段落-每页显示一定数量的段落的主要内容,如果未能解决你的问题,请参考以下文章