Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using following snippet to output pagination:

// get the current page     
if ( get_query_var('paged') ) {
    $current_page = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $current_page = get_query_var('page');
} else {
    $current_page = 1;
}

// structure of “format” depends on whether we’re using pretty permalinks
$permalink_structure = get_option('permalink_structure');
$format = empty( $permalink_structure ) ? '&page=%#%' : 'page/%#%/';

echo paginate_links(array(
      'base' => get_pagenum_link(1) . '%_%',
      'format' => $format,
      'current' => $current_page,
      'total' => $total,
      'mid_size' => 4,
      'type' => 'list'
));

When I set permalink type to http://wordpress/?p=123 and use static page for frontpage with pagination, I recieve wrong URLs like:

http://wordpress/&page=2

instead of:

http://wordpress/?page=2

If you navigate to http://wordpress/?page=2, links in pagination will be also wrong, because current URL with queries goes as a base, for example:

http://wordpress/?page=2&page=3

If I use any other permalink type with rewriting, everything works fine.

I'm looking any solution for this snippet and frontpage pagination.

Thanks in advance for any help.

UPDATE: My main problem was a mistype at &page=%#% but actually i need &paged=%#% and i add condition with is_front_page() function to switch & to ? for frontpage query.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I think that's because the code is doing strictly what you're telling it to do, here:

$format = empty( $permalink_structure ) ? '&page=%#%' : 'page/%#%/';

Note: '&page=%#%'.

Try building your permalink structure using add_query_arg(), which handles proper appending of & vs ?.

share|improve this answer
    
Can you help me here wordpress.stackexchange.com/q/57593/12261 –  Ajay Patel Jul 6 '12 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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