Crib a bit of code from wp-includes/query.php
and bit from wp-includes/post-template.php
, add a little, mix and stir, and…
function url_to_last_page() {
global $post;
$content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $post->post_content);
$content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
$content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
$pages = explode('<!--nextpage-->', $content);
$numpages = count($pages);
$ret = _wp_link_page($numpages);
$ret .= $numpages;
$ret .= '</a>';
return $ret;
}
echo url_to_last_page();
wp_list_pages
works on index pages so WordPress had to know how to build the links. I just had to find the relevant bits. That need to be inside a Loop, as it depends on the global $post
variable. It could be edited to accept a parameter to make it more flexible.