Pagination plugin breaks with permalinks?

Hi all, I’m trying to get to the bottom of an issue I’m having with a plugin called “simple pagination” (link). The site in question is “pahra.org” under the “members” page of the main navigation there are drop-downs with categories, once selected, these return a set of pages for the chosen category. Using the “next” or “prev” buttons at the bottom then takes you from page to page.

This works perfectly whenever default permalinks (ex “?page_id=148”:wink: are in use. Here’s an example from my testing site where I’m using default permalinks. As you can see, the next and previous buttons work correctly.

With permalinks setup with postnames (for SEO), the pagination setup stops working. Here is the problem on the same page of my live site with permlinks using postnames. Using the “next” button at bottom returns a blank page and this URL: “http://pahra.org/members/housing-authorities/?region_name=Central/page/2/”.

Below is the code I am using for the “simple pagination” plugin. Can anyone give me a hand with getting this plugin to return the needed URLs so these category pages will work with my postname permalinks?

code:

function generateOutput( $args = array() )
{

$this->options = wp_parse_args( $args, $this->options);

global $wp_query, $wp_rewrite;

// value of the current page

if( $this->options['type'] == 'comments' ) {

$wp_query->query_vars['cpage'] > 1 ? $current = $wp_query->query_vars['cpage'] : $current = 1; // Current page
$total = $wp_query->comment_count; // Total comments
$this->add_fragment = '#comments'; // Add fragment to URL
$range = $this->options['comments_range']; // Range
$anchor = $this->options['comments_anchor']; // Anchor
$large_page_multiple = $this->options['comments_larger_page_multiple']; // Large page multiple
$larger_page_to_show = $this->options['comments_larger_page_to_show']; // Large page to show
$always_show = $this->options['comments_always_show']; // Always show
$show_all = $this->options['comments_show_all']; // Show all
}
else {

$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1; // Current page
$total = $wp_query->max_num_pages; // Total posts
$range = $this->options['range']; // Range
$anchor = $this->options['anchor']; // Anchor
$large_page_multiple = $this->options['larger_page_multiple']; // Large page multiple
$larger_page_to_show = $this->options['larger_page_to_show']; // Large page to show
$always_show = $this->options['always_show']; // Always show
$show_all = $this->options['_show_all']; // Show all
}

$start_page = $current - floor( $range/2 );

if ( $start_page <= 0 )
$start_page = 1;

$end_page = $current + ceil( ($range+1)/2 );

if ( ( $end_page - $start_page ) != $range )
$end_page = $start_page + $range;

if ( $end_page > $total ) {
$start_page = $total - $range;
$end_page = $total;
}

// Rewrite link
if( $wp_rewrite->using_permalinks() )
if( $this->options['type'] == 'comments' )
$this->base = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');

else
$this->base = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
else {
if( $this->options['type'] == 'comments' )
$this->base = @add_query_arg('cpage','%#%');
else
$this->base = @add_query_arg('paged','%#%');
}

// Search value
if( !empty($wp_query->query_vars['s']) )
$this->add_args = array( 's' => get_query_var( 's' ) );

// Check of pagination is always show and check if the total of pages is egal 1
if( !$always_show && $total == 1 )
return false;

// Text of the beginning
$text_pages = str_replace( array( "%CURRENT_PAGE%", "%TOTAL_PAGES%" ),
array( number_format_i18n( $current ), number_format_i18n( $total ) ),
$this->options['text_pages']
);

// Before link Markup
$before_link = html_entity_decode($this->options['before_link']);

// After link Markup
$after_link = html_entity_decode($this->options['after_link']);

// Beginning of the HTML markup of pagination
$this->output .= html_entity_decode($this->options['before_pagination']);
if( $text_pages )
$this->output.= '<span class="pages">' . $text_pages . '</span>';

// First Page
/*if( $current-1 > floor($range+1/2) ) :

$link = $this->formate_link(1);

if( $this->options['text_first_page'] )
$this->output .= $before_link . '<a class="first" href="' . esc_url($link) . '">' . $this->options['text_first_page'] . '</a>' . $after_link;

endif;*/

$larger_pages_array = array();
if ( $large_page_multiple )
for ( $i = $large_page_multiple; $i <= $total; $i+= $large_page_multiple )
$larger_pages_array[] = $i;

$larger_page_start = 0;
foreach ( $larger_pages_array as $larger_page ) {
if ( $larger_page+floor(($range+1)/2) < $start_page && $larger_page_start < $larger_page_to_show ) {

$link = $this->formate_link($larger_page);

$this->output .= $before_link . '<a class="larger-pages" href="' . esc_url($link) . '">' . $larger_page . '</a>' . $after_link;
$larger_page_start++;
}
}

//Previous Page
$this->output .= '<li>';
if ( $current && 1 < $current ) :
$link = $this->formate_link($current - 1);
if( $this->options['text_previous_page'] )
$this->output .= $before_link . '<a class="previous" href="' . esc_url($link) . '">' . $this->options['text_previous_page'] . '</a>' . $after_link;
endif;
$this->output .= '&nbsp;</li>';

$this->output .= '<li>';
for ( $n = 1; $n <= $total; $n++ ) :
$n_display = number_format_i18n($n);
if ( $n == $current ) :
//$this->output .= $before_link . '<span class="current">' .$n_display . '</span>' . $after_link;
$this->output .= '<span class="greyPage">Page</span> '.$n_display.' <span class="greyPage">of</span> '.$total.'</li>';
$dots = true;
else :

/*if ( $show_all || ( $n <= $anchor || ( $current && $n >= $current - $range && $n <= $current + $range ) || $n > $total - $anchor ) ) :

$link = $this->formate_link($n);

$this->output .= $before_link . '<a href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">'. $n_display . '</a>' . $after_link;
$dots = true;

elseif ( $dots && !$show_all && $anchor >=1 ) :
$this->output .= $before_link . '<span class="dots">...</span>' . $after_link;
$dots = false;
endif;*/
endif;
endfor;
$this->output .= '</li>';
// Next Page

$this->output .= '<li>';
if ( $current && ( $current < $total || -1 == $total ) ) :

$link = $this->formate_link(number_format_i18n($current + 1));

if( $this->options['text_next_page'] )
$this->output .= $before_link . '<a class="next" href="' . esc_url($link) . '">' . $this->options['text_next_page'] . '</a>' . $after_link;
endif;
$this->output .= '</li>';

$larger_page_end = 0;
foreach ( $larger_pages_array as $larger_page ) {
if ( $larger_page-(floor($range/2)) > $end_page && $larger_page_end < $larger_page_to_show ) {

$link = $this->formate_link($larger_page);

$this->output .= $before_link . '<a class="larger-pages" href="' . esc_url($link) . '">' . $larger_page . '</a>' . $after_link;

$larger_page_end++;
}
}

// Last Page
/*if( $current < $total-(floor($range+1/2)) ) :

$link = $this->formate_link($total);

if( $this->options['text_last_page'] )
$this->output .= $before_link . '<a class="last" href="' . esc_url($link) . '">' . $this->options['text_last_page'] . '</a>' . $after_link;

endif;
*/

$this->output.= html_entity_decode($this->options['after_pagination']);

echo $this->output;
}

/**
* method formate_link
*
* @since 1.O
*/
function formate_link( $page )
{
$link = str_replace('%_%', "?page=%#%", $this->base);
$link = str_replace('%#%', $page, $link);
$link = str_replace('page/1/','', $link);
$link = str_replace('?paged=1','', $link);

if ( $this->add_args )
$link = add_query_arg( $this->add_args, $link );

if( $this->add_fragment )
$link .= $this->add_fragment;

return str_replace(' ','+', $link);
}

}

// Start this plugin once all other plugins are fully loaded
global $Simple_Pagination; $Simple_Pagination = new Simple_Pagination();

/**
* method wp_simple_pagination
*
* Affiche le contenu de la pagination.
*
* @since 1.O
*/

function wp_simple_pagination( $args = array() )
{
$Simple_Pagination = new Simple_Pagination();
echo $Simple_Pagination->generateOutput( $args );
}

/**
* method wp_simple_comments_pagination
*
* Affiche le contenu de la pagination.
*
* @since 2.O
*/
function wp_simple_comments_pagination( $args = array() )
{
global $Simple_Pagination;
$args['type'] = 'comments';
echo $Simple_Pagination->generateOutput( $args );
}