WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Automatically insert <!--nextpage-->? (3 posts)

  1. Michael Dance
    Member
    Posted 5 years ago #

    I'm trying to automatically insert <!--nextpage--> into all posts after a certain word count. Seems like it should be easy, but it's not.

    (AJAXed WordPress seems to be the only plugin that provides a similar functionality to what I need, but in order to use it you have to deal with the other 95 things that plug-in does and I'm trying to avoid that.)

    Before you tell me that nextpage is bad for usability or I shouldn't breakup pages mid-sentence: I know. I need to do it anyway.

    I'm a reasonably good coder so if you just want to point me in the right direction with a php snippet or something, that'd be great. I'm just hitting a brick wall here.

  2. Michael Dance
    Member
    Posted 5 years ago #

    To anybody stumbling across with the same issue, my solution was to insert the <!--nextpage--> tag directly into the post_content row in the database. After querying the database for the post_content of this post's postID...

    $row = mysql_fetch_assoc($result);
    $thepost = $row["post_content"];
    
    $text = explode(" ", $thepost);
    
    if (isset($text[500]) && $text[500] != "<!--nextpage-->") {
    array_splice($text, 500, 0, "<!--nextpage-->");
    } else {
    }
    $newpost = implode(" ", $text);

    ...then do another mysql query and set the post_content row of the post to $newpost.

    For a different word count, replace all the instances of "500" in there with whatever word count you want.

    It's a messy, imperfect solution, and there's assuredly a better way but I'm pretty new to php. You have to refresh the page before the changes go into effect, and if you ever edit the page afterwards, you have to strip out the <!--nextpage--> tags so you don't end up with more than you want.

  3. Geet Jacobs
    Member
    Posted 5 years ago #

    Hello there,

    I am looking to do as mentioned above, was hoping for a plugin but surprisingly there aren't any.

    Maybe i have this wrong but you actually go into the database and edit queries? No other way with hook or in single.php page php code?

    I dont trust myself messing with the database.

    Thanks for your time!

    Dale Jacobs

Topic Closed

This topic has been closed to new replies.

About this Topic