Guest User

Untitled

a guest
Sep 18th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. // Auto Paging
  2. function auto_paging($post) {
  3.     global $page, $pages, $multipage, $more, $numpages;
  4.     $content = $post->post_content;
  5.     if (!strpos($content, '<!--nextpage-->')) {
  6.         preg_match_all("#(<p[^>]*>(.*)</p>|<h[^>]*>(.*)</h(.*)>)#isU", $content, $paragraphs);
  7.         $count = 1;
  8.         $max_paragraph = 8;
  9.         foreach($paragraphs[0] as $paragraph) {
  10.             if ($count != $max_paragraph) {
  11.                 $count++;
  12.                 $temp_content = $temp_content.$paragraph;
  13.             }
  14.             else {
  15.                 $count = 1;
  16.                 $temp_content = $temp_content.$paragraph."<!--nextpage-->";
  17.             }
  18.         }
  19.         $content = $temp_content;
  20.         if( $page > 1 ) $more = 1;
  21.         $multipage = 1;
  22.         $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
  23.         $content = str_replace("\n<!--nextpage-->",'<!--nextpage-->', $content);
  24.         $content = str_replace("<!--nextpage-->\n",'<!--nextpage-->', $content);
  25.         $pages = explode('<!--nextpage-->', $content);
  26.         $numpages = count($pages);
  27.         $post->post_content = $content;
  28.     }
  29. }
  30. add_action( 'the_post', 'auto_paging' );
Add Comment
Please, Sign In to add comment