I'm using the code below to create pagination for my post results, it works fine but is it possible to add a "view all posts on one page" button to the pagination?

This would presumably override the pagination code and just display everything all posts on one page.

function numeric_pagination ($pageCount = 9, $query = null) {

if ($query == null) {
    global $wp_query;
    $query = $wp_query;

if ($query->max_num_pages <= 1) {

$pageStart = 1;
$paged = $query->query_vars['paged'];

// set current page if on the first page
if ($paged == null) {
    $paged = 1;

// work out if page start is halfway through the current visible pages and if so     move it accordingly
if ($paged > floor($pageCount / 2)) {
    $pageStart = $paged - floor($pageCount / 2);

if ($pageStart < 1) {
    $pageStart = 1;

// make sure page start is 
if ($pageStart + $pageCount > $query->max_num_pages) {
    $pageCount = $query->max_num_pages - $pageStart;

<div id="pagination">
if ($paged != 1) {
<a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first">  <span>&lsaquo; <?php _e('Newest', 'rhinoplasty'); ?></span></a>
// first page is not visible...
if ($pageStart > 1) {
    //echo 'previous';
for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) {
    if ($p == $paged) {
    <span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?    php echo $p; ?></span>
<?php } else { ?>
    <a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?    php echo $p; ?>"><span><?php echo $p; ?></span></a>

// last page is not visible
if ($pageStart + $pageCount < $query->max_num_pages) {
    //echo "last";
if ($paged != $query->max_num_pages) {
    <a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('Oldest', 'rhinoplasty'); ?> &rsaquo;</span></a>
<?php } ?>


<?php }

I'm not really sure how to go about doing this, any suggestions would be greatly appreciated. Changing to different pagination code is also fine if that will work better.

Just to clarify my question, I want to add a 'view all posts on one page' functionality, basically over-riding the pagination code - this would be done by clicking a "view all" link to the right of the pagination menu ( 4 5 ... last Next >> View All> ).

Update - almost there I think:

I've added this:

$nopage = add_query_arg( 'paged', 'no', $Path );

<a href="<?php echo $nopage; ?>">View All</a>

Which reloads my page with sitename.com?paged=no, but it still shows pagination - I'm not sure how to override the pagination.


Here is how I ended up solving it in case this helps anyone else.

After the above code and before the final I added:

if (isset($_GET['viewall']))


function view_allposts( $query ) {

    $query->set( 'posts_per_page', -1 );


add_action( 'pre_get_posts', 'view_allposts' );


if(!$_GET['viewall']){ ?>

<a class="numbered" href="<?php  echo add_query_arg( array( 'viewall' => "true" ), get_pagenum_link(1) ); ?>">Show All >></a>

<?php } ?>

Works perfectly! Thanks for your help on this Kaiser, although I used a different solution I learned a lot from the links you provided.


You could use add_query_arg() and change $paged for the old query.


//  This should output 'http://example.com/?paged=no'
add_query_arg( 'paged', 'no', bloginfo('url') );

Then use get_query_var() to modify the output.

  • Thanks kaiser, how would I implement that? – maikunari Jun 24 '11 at 19:44
  • See edited A... – kaiser Jun 24 '11 at 20:09
  • I've been trying to work this out but my knowledge is pretty limited, do you think you could give me a bit more detail on how to make this work? – maikunari Jun 24 '11 at 21:59
  • Sure. Just post what you already tried, then I'll help you with the next step. – kaiser Jun 25 '11 at 9:14
  • Sorry for the delay, couldn't get to my work computer this weekend! I've edited the above to show what I've come up with (not much unfortunately) – maikunari Jun 27 '11 at 15:58

Filter 'pre_get_posts' and set the nopaging parameter to true.

I have written a small tutorial about this: How To List All Posts Of An Archive, A Category Or A Search Result.

  • That is awesome. – maikunari Jul 3 '11 at 14:42

My company just released a plugin that offers publishers the option of including a "single page" link in their pagination strings: Page-Links Plus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.