[resolved] Automatic split long post into multi page (9 posts)

  1. solitary1510
    Posted 3 years ago #

    Just edit /wordpress_folder/wp-includes/query.php

    $pages = array( $post->post_content );
    		$multipage = 0;

    Replace with

    preg_match_all("#<p(.*?)</p>#", $content, $paragraphs);
    		$count = 0; $max_paragraph = 10;
    		foreach ($paragraphs[0] as $paragraph) {
    			if ($count == $max_paragraph) {
    				$content = str_replace($paragraph, $paragraph."<!--nextpage-->", $content);
    				$count = 0;
    			else $count++;
    		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);

    I split post to multi page and each page have 10 paragraph. Maybe it's only work for me. Of course, you can split base number of image, word,...

    1 question I want ask that maybe write plugin like this to auto split long post or any edit in themes.

    Edit core is work for me but maybe not a good way.

    Sorry for my bad English. And thanks for any support...

  2. Tara
    Volunteer Moderator
    Posted 3 years ago #

    check thois plugin and see if it will work for you: http://wordpress.org/extend/plugins/adjustly-nextpage/

  3. solitary1510
    Posted 3 years ago #

    @t-p: I don't think it auto split long page

    We did not create any new features with this plugin, it simply brings back an existing feature to the toolbar.

  4. Tara
    Volunteer Moderator
    Posted 3 years ago #

    Just insert <!--nextpage--> where you need the break, and a properly coded theme will create pagination links.

    codex: http://codex.wordpress.org/Function_Reference/wp_link_pages

  5. solitary1510
    Posted 3 years ago #

    @t-p: of course I know it. Do you see "auto" word? Just think about 1 post have ~10 000 words. It crazy to manual insert <!--nextpage-->

  6. bcworkz
    Posted 3 years ago #

    You should be able to make a plugin out of your code. All the important vars are available as globals. There's an action hook, 'the_post' right after your insertion that could be used. Not really sure how to use ref_array hooks though.

    Ideally, find a hook just before this function is called, then you don't have to replicate the <!--nextpage--> code.

    Personally, I dislike multi-page posts, no doubt others prefer it, as I see it all the time, to my annoyance. :)

  7. solitary1510
    Posted 3 years ago #

    @bcworkz: Can you make me some suggestion for?

    I'm also like you :). If can make a plugin, I will split page just for Mobile Users :). Long post can make some phone out of memory and ops... Phone restart :)

  8. bcworkz
    Posted 3 years ago #

    Ah, mobiles! I'm ashamed to admit I often neglect this increasingly important segment.

    I poked around a bit, looks like 'the_post' is the only hook available. Looks like you still use add_action() to hook ref_array actions, it's just you get a single array of arguments instead of comma separated arguments.

    Plugin would be roughly:

    /* plugin specific headers go here...*/
    add_action('the_post', 'bcw_paginate');
    function bcw_paginate($post) {
      global $page, $pages, $multipage, $more, $numpages;
      $content = $post->post_content;
      //Insert your code here...
      return $post;
  9. solitary1510
    Posted 3 years ago #

    Sr for late reply. It's work. Thanks for suggestion :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.