logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Gabriel Reguly

Website Twitter



Written in response to Paginate this post query.:

My solution had a flaw, where the first page of pagination always redirected to the current page.

Follows amended solution:


<?php
/*
Template Name: Sitemap Extreme
*/
add_filter( 'paginate_links', 'my_pagination' );

function my_pagination( $link ) {
if ( empty( $link ) ) { // no link? Then we link to the 1st page.
$link = '?page=1';
}
return $link;
}

foreach( get_post_types( array('public' => true) ) as $post_type ) {
if ( in_array( $post_type, array('post','page','attachment') ) )
continue;
$pt = get_post_type_object( $post_type );
echo '<h2>'.$pt->labels->name.'</h2>';
echo '<ul>';
$my_page = (get_query_var('page')) ? get_query_var('page') : 1;
// get 25 posts per page
query_posts('post_type='.$post_type.'&posts_per_page=25&paged=' . $my_page);
while( have_posts() ) {
the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
echo '</ul>';
global $wp_query;
$big = 999999999; // need an unlikely integer

$args = array(
'current' => $my_page,
'total' => $wp_query->max_num_pages);
echo paginate_links( $args );
}
?>


Updated: 01/13/12 3:10pm


Upvote / Downvote

3 groups of people are allowed to vote for discourse:

All votes are public.

You are not allowed to vote: