I need a method to automatically create pages (using <!--nextpage-->
) in posts based on number of words.
For example… A post containing 1200 words should be broken down into 6 pages with page break coming after every 200 words.
I understand that I can do it manually. But this functionality is needed for a site powered by WordPress that would contain archives of imported data in multiple languages.
Tried searching for a plugin that would accomplish something like this. Could not find it.
This is tough to do programmatically because of potential variations in html and how the tags balance. However, if you were to try, here’s how I’d suggest doing it.
First of all, WordPress sets up the post pagination in
setup_postdata()
, which is called at the end ofthe_post()
. That means you need to get those<!--nextpage-->
lines in the posts before the end ofthe_post()
. The'loop_start'
action should work for those purposes. It even passes a copy of the current WP_Query object by reference, so you can make changes directly to the queried posts!Something like this is a start:
Hopefully that gives you an idea of what you would need to do. I’d suggest finding some way of temporarily stripping html tags and replacing them after inserting the
nextpage
flags, because the function above will also count spaces inside HTML tags, and could even put a page break inside one.Thanks for saving my time. While migrating non wordpress site in to wordpress i was trying to replace PAGEBREAK in to wordpress I have done this with following syntax.
Studio Hyperset’s Page-Links Plus “auto pagination” module can help you accomplish this.
It allows WordPress users to trade tedious in-line tags for a site-wide management tool that paginates posts and pages quickly and uniformly.
The module automatically prevents widows, orphans, trailing headers, and avoids splitting sentences and individual words and can be configured to override or ignore existing in-line tags.
Check it out here: http://pagelinksplus.com/wordpress-pagination-modules/wordpress-pagination-auto-pagination