Add code just after Post content

I am in a bit of dilemma here so bare with me. I want to add something like this code just after the content in a post:

<p>Please let me know what you think by <a href="#comment">leaving a comment</a>!</p>

To do this, I edited single.php and added it after the content. However, the problem is that many of my posts are separated in several pages by using <!--nextpage--> and the above code is displayed on every page. I want that line to be displayed only at the final page if the post is separated. How is such thing possible?

Related posts

Leave a Reply

1 comment

  1. There are some global variables available (or not) to detect the current page number:

    if ( empty ( $GLOBALS['multipage'] ) or $GLOBALS['numpages'] === $GLOBALS['page'] )
        echo '<a id="lastPageLink" href="#comment">comment</a>';
    

    The best way to understand what they do is a look at the internals of wp_link_pages().

    • (bool) $GLOBALS['multipage'] is TRUE if there is more than one page.
    • (int) $GLOBALS['numpages'] is the amount of available pages.
    • (int) $GLOBALS['page'] is the number of the current page.

    In JavaScript you can add an onclick handler like this now:

    document.getElementById("lastPageLink").onclick = function() {
        window.location.hash = 'comment';
        document.getElementById('comment').focus();
        return false;
    }