• OK I think I’ve gone part of the way towards solving the persistent issue of getting the nextpage tag to work in a home page; please note this is not yet a complete solution, and it’s also pretty crude coding; at this iteration the more tag doesn’t work with this code, and the homepage checking is not yet sufficiently rigorous to overcome all possible error conditions – see the foot of https://cmslamp.com/category/wordpress/ for discussion and a possible better checking method.

    In your main page template immediately after the header call, insert

    <?php /* required when home page has "nextpage" tag */ global $more; ?>

    In your main page template immediately before the get the content call insert

    <?php /* required when home page has "nextpage" tag */ $more = 0; ?>

    In your main page template immediately after the content call, insert

    <?php /* for nextpage tag processing */
    
    if (is_front_page() != 0) {
    
    /* DEBUG ONLY echo "<br />The home page ID is " . get_the_ID(); */
    /* DEBUG ONLY find the number of subpages and display number if more than 1 */
    // if (isset($numpages)) {if ($numpages >=2) {echo "<br />The number of pages is "; echo $numpages; }}
    
    ?>
    
    <p></p>
    <?php 
    
    $i = 1;
    if ($numpages >=2) {
    
    echo "<h4>PAGES: ";
    while ($i <= $numpages):
    $gopt = get_option('siteurl');
    $npage = "/?page_id=";
    $gid = get_the_ID();
    $spage = "&page=";
    $spagenum = $i;
    
    $string1 = $gopt . $npage . $gid . $spage . $spagenum;
    
        echo "<a href='$string1'>" . $i . "</a> " ;
        $i++;
    endwhile;
    
    echo "</h4>"; }
    ?>
    
    <?php
    
    } else { wp_link_pages('before=<p>&after=</p>&next_or_number=number&pagelink=page %');}
    
    /* end homepage processing for nextpage links */  ?>

    As I said, it’s crude, but I’d welcome feedback; if after further dev/testing it is still robust in several themes then I may consider rewriting it for a plugin architecture with filters.

    Robert

  • The topic ‘Possible solution: “nextpage” on a static homepage’ is closed to new replies.