Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Auto Paging
- function auto_paging($post) {
- global $page, $pages, $multipage, $more, $numpages;
- $content = $post->post_content;
- if (!strpos($content, '<!--nextpage-->')) {
- preg_match_all("#(<p[^>]*>(.*)</p>|<h[^>]*>(.*)</h(.*)>)#isU", $content, $paragraphs);
- $count = 1;
- $max_paragraph = 8;
- foreach($paragraphs[0] as $paragraph) {
- if ($count != $max_paragraph) {
- $count++;
- $temp_content = $temp_content.$paragraph;
- }
- else {
- $count = 1;
- $temp_content = $temp_content.$paragraph."<!--nextpage-->";
- }
- }
- $content = $temp_content;
- if( $page > 1 ) $more = 1;
- $multipage = 1;
- $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
- $content = str_replace("\n<!--nextpage-->",'<!--nextpage-->', $content);
- $content = str_replace("<!--nextpage-->\n",'<!--nextpage-->', $content);
- $pages = explode('<!--nextpage-->', $content);
- $numpages = count($pages);
- $post->post_content = $content;
- }
- }
- add_action( 'the_post', 'auto_paging' );
Add Comment
Please, Sign In to add comment