• I would like the pagination of a certain page to look like this:

    site.com/page-name/page/2/paged2/1

    so I used this:

    <?php 
    global $wp_rewrite, $wp_query_videos;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    //$paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;	
    
    (isset($wp_query->query_vars['paged2']) ? ($wp_query->query_vars['paged2'] > 1 ? $current2 = $wp_query->query_vars['paged2'] : $current2 = 1) :  $current2 = 1) ;
    
    $big = 999999999; // need an unlikely integer
    $classiera_pagination = array(
    	//'base' => str_replace($big,"{$current}/paged2/%#%", esc_url( get_pagenum_link( $big ) ) ),
    	'format' => 'page/%#%',
    	'total' => $wp_query_videos->max_num_pages,
    	'current' => $current2,
    	'show_all' => false,
    	'type' => 'plain',
    	//'add_args' => array( 'paged' => $current, 'paged2' => $paged2)
    	);
    
    if( $wp_rewrite->using_permalinks() )
    	$classiera_pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . "page/{$current}/paged2/%#%", 'paged');
    /*
    if( !empty($wp_query->query_vars['s']) )
    	$classiera_pagination['add_args'] = array('s'=>get_query_var('s'));
    */
    echo '<div class="pagination">' . paginate_links($classiera_pagination) . '</div>'; 
    ?>

    and this rules of rewriting

    function wpse21802_init(){
    	global $wp_rewrite; 
    	$wp_rewrite->flush_rules();
      add_rewrite_rule( '([^/]+)/page/([^/])/?$', 'index.php?pagename=$matches[1]&paged=$matches[2]');
      add_rewrite_rule( '([^/]+)/page/([^/])/paged2/([^/])/?$', 'index.php?pagename=$matches[1]&paged=$matches[2]&paged2=$matches[3]');
    
    }
    add_action( 'init', 'wpse21802_init', 10, 0);

    but a problem happens … after I use the page once to go for example to page 2

    site.com/page-name/page/1/paged2/2/

    the paging links are getting like this for page 1

    site.com/page-name/page/1/paged2/2/page/1/paged2/1/
    This is generating error at the time of paging. What may be the problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It did what you told it to, the problem is that what you told it to do wasn’t what you really wanted.
    WP already has working paging. Trying to change it using the same variables is not a good idea.

    Thread Starter atrevid0

    (@atrevid0)

    Spent lots of characters to help nothing. I know WP has paging system, but if I’m using custom it’s because I need it.

    I’m still after the help to understand what I’m doing wrong.

    Regular expressions are greedy, which means that if ‘/page/’ is in there twice, it will match the last one, and everything before it will be in ‘$matches[1]’. And why have two rules, when the first one would match so you never even look at the second one?
    This is what I was talking about using the same variables already being used.

    If you need a custom paging, use your own custom variables, not WP’s variables.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Paginate links repeating value in links’ is closed to new replies.