8000 Improved Pagination · Issue #318 · roots/sage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Improved Pagination #318
Closed
Closed
@zslabs

Description

@zslabs

Hey Ben,

The default post navigation uses the standard, boring Older Posts or Newer Posts

<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ($wp_query->max_num_pages > 1) { ?>
  <nav id="post-nav" class="pager">
    <div class="previous"><?php next_posts_link(__('&larr; Older posts', 'roots')); ?></div>
    <div class="next"><?php previous_posts_link(__('Newer posts &rarr;', 'roots')); ?></div>
  </nav>
<?php } ?>

Referencing http://wp.tutsplus.com/tutorials/wordpress-pagination-a-primer/ I think a much more usable alternative would be the following:

<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php
    global $wp_query;  
    $total_pages = $wp_query->max_num_pages;  
    if ($total_pages > 1){  
        $current_page = max(1, get_query_var('paged'));  
        echo '<div class="page_nav">';  
        echo paginate_links(array(  
            'base' => get_pagenum_link(1) . '%_%',  
            'format' => 'page/%#%',  
            'current' => $current_page,  
            'total' => $total_pages,  
            'prev_text' => 'Prev',  
            'next_text' => 'Next'  
        ));  
        echo '</div>';  
    } 
?>

As it states in the article, this will put both Prev, Next and page numbers as well.

I know I keep throwing these code changes at you - I'll sit down and learn how to properly do these through GitHub soon :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0