View All
In order for the page to be viewed in its entirety instead of being paged, the page source must be modified prior to being displayed in the post or page display. This is handled by the following functions:
1 2 3 4 5 6 7 8 9 10 11 | function wp_link_pages_extended_the_post( $post ) { global $pages, $multipage, $wp_query; if ( isset( $wp_query -> query_vars[ ‘viewall’ ] ) && ( ‘true’ === $wp_query -> query_vars[ ‘viewall’ ] ) ) { $multipage = true; $post -> post_content = str_replace( ‘<!–nextpage–>’, ‘<hr class=“wp-link-pages-extended” style=“clear:both;” />’, $post -> post_content ); $pages = array( $post -> post_content ); } } |
This routine fires during post display. First it checks whether the ‘viewall’ parameter is in the URL and then checks the value of the parameter for ‘true’. Then is replaces any appearance of <!--nextpage-->
with <hr class="wp-link-pages-extended" style="clear:both;"/>
so that the page separations are indicated by horizontal lines.
If there are no pages, then the page links are not shown and there is no way to return to the paged format, unless the routine supplies it. Fortunately there is a solution. The same functionality can be added to the function to display the ‘View Pages’ links. In this situation, only the ‘First’ and ‘Last’ links are included.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | if ( isset( $wp_query -> query_vars[ ‘viewall’ ] ) && ( ‘true’ === $wp_query -> query_vars[ ‘viewall’ ] ) ) { /* * Count the true number of pages here, somewhere it is being reset in certain situations */ $numpages = substr_count( $post -> post_content, ‘class=“wp-link-pages-extended“ ‘ ) + 1; /* * Before page: open section */ $args[ ‘before’ ] .= ‘<div style=“clear:both; display:block; text-align: center;” >’; $args[ ‘before’ ] .= ‘<p class=“post-pagination”>’; /* * Before page: first page link * (Using get_pagenum_link() here also returns the “viewall=true” parameter which defeats the purpose of the link */ $args[ ‘before’ ] .= _wp_link_page( 1 ) . $args[ ‘firstpagelink’ ] . ‘</a>’; $args[ ‘before’ ] .= $args[ ‘separator’ ]; /* * After page: final links */ $args[ ‘after’ ] .= $args[ ‘separator’ ]; $args[ ‘after’ ] .= _wp_link_page( $numpages ) . $args[ ‘lastpagelink’ ] . ‘</a>’; /* * View All link handing */ $args[ ‘after’ ] .= ‘<br/>’ . $args[ ‘viewpageslink’ ]; $args[ ‘after’ ] .= ‘</p>’; $args[ ‘after’ ] .= ‘</div>’; return( $args ); } |
During testing, I discovered that in certain situations, the $numpages
counter was being reset to 1 after the page or post contents were modified to remove the <!--nextpage-->
markers. (I suspect it was the theme doing that.) For that reason, the function also reset the value of the counter the actual number of pages, because otherwise the wp_link_pages()
function would not return any links.
Personal Links
My Amazon Wishlist
My DeviantArt Gallery
My Facebook Page
My Goodreads Bookshelf
My Smashwords Catalog
My Twitter Feed
My WordPress Profile