Wordpress page navigation within posts
I have a page template in wordpress that only shows posts from a specific category with ID 972. I've limited it so that it displays 8 posts on the page. I was wondering if it would be pos开发者_如何学JAVAsible to display page navigation at the bottom, so that I could go to the next post page ONLY from the posts with category ID 972. Is this possible?
EDIT:
the post_nav_link();
function doesn't work for me...
Thanks! Amit
Ah, ok. My bad, interpreted that wrong.
I had this snippet floating around (not from me, no idea where I found it):
function pagination( $query, $baseURL )
{
$page = $query->query_vars["paged"];
if ( !$page ) $page = 1;
$qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
// Only necessary if there's more posts than posts-per-page
if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
echo '<ul class="paging">';
// Previous link?
if ( $page > 1 ) {
echo '<li class="previous"><a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'">« Previous page</a></li>';
}
// Loop through pages
for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
// Current page or linked page?
if ( $i == $page ) {
echo '<li class="active"><span>'.$i.'</span></li>';
} else {
echo '<li><a href="'.$baseURL.'page/'.$i.'/'.$qs.'">'.$i.'</a></li>';
}
}
// Next link?
if ( $page < $query->max_num_pages ) {
echo '<li class="next"><a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'">Next page »</a></li>';
}
echo '</ul>';
}
}
It takes a query object (your category query) and a base url (your archive page) and generates a pagination. Maybe this works for you.
http://codex.wordpress.org/Function_Reference/previous_post_link http://codex.wordpress.org/Function_Reference/next_post_link
This is impossible to do as the link only works on categories / archived pages. The link goes to something like URL/category/page/[page#]
Oh well.
精彩评论