/ Published in: PHP
For a client I needed a bit of code that could split one file (html, editable through wysiwyg editor) to multiple files, since all files would by default become very long. This code splits one file by the tag. Easy for end-users to set. Use CSS to style the pagination links (<ul> list)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<? // Specify the source file (e.g.: ../../files/myfile.html) // Add an extra <h1> tag to prevent it getting lost during explode // Explode the source file for each <h1> tag // Count the total number of <h1>'s. (My system needs -1, could be my mistake) // If not ?page= is set, then go by default to page 1 (first <h1>) // Set (for later use) the current page +1 and -1 $page_next = $page+1; $page_prev = $page-1; // This shows the current page (could be more sophistaced ofcourse) echo($explode[$page]); ?> <hr/> <div id="pagination"> <ul> <? // If page is not 1, then show previous and first echo ($page!='1')?'<li><a href="?module=cms&cms_id='.$_GET['cms_id'].'&page=1">Eerste</a></li><li><a href="?module=cms&cms_id='.$_GET['cms_id'].'&page='.$page_prev.'">Vorige</a></li>':null;?> <? // Show each and every page available (1, 2, 3, 4...) for ($i=1; $i<=$numpage ; $i++) { echo ($i==$page)?'<li><strong>'.$i.'</strong></li>':'<li><a href="?module=cms&cms_id='.$_GET['cms_id'].'&page='.$i.'">'.$i.'</a></li>';} ?> <? // Show next and last page when not already at last page echo ($page!=$numpage)?'<li><a href="?module=cms&cms_id='.$_GET['cms_id'].'&page='.$page_next.'">Volgende</a></li><li><a href="?module=cms&cms_id='.$_GET['cms_id'].'&page='.$numpage.'">Laatste</a></li>':null;?> </ul> </div>