Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter nikixiaoyou

    (@nikixiaoyou)

    I finally figured it out by myself. If anyone is also struggling with this issue, I found out that the links generated in the get_pagenum_link function from the link-template.php file (located in wp-includes) were broken when the site was in a language different from the default one.
    Since this function is only called when loading more pages and not the first one (which is the case with the theme we’re using), this bug was only showing up after the 10th post, which is the max post per page set in the “Blog pages show at most” setting.
    Here is the updated function. You might have to make a few changes to make it fit with your languages, and by no means is this a good long-lasting solution. But it’s a workaround!

    function get_pagenum_link($pagenum = 1, $escape = true ) {
    	global $wp_rewrite;
    
    	$languageArray = array("?lang=fr", "?lang=en");
    
    	$pagenum = (int) $pagenum;
    
    	$request = remove_query_arg( 'paged' );
    
    	$home_root = parse_url(home_url());
    	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
    	$home_root = preg_quote( $home_root, '|' );
    
    	$request = preg_replace('|^'. $home_root . '|i', '', $request);
    	$request = preg_replace('|^/+|', '', $request);
    
    	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
    		$base = trailingslashit( get_bloginfo( 'url' ) );
    
    		if (strpos($base, '?lang=') !== FALSE)
    			$base = str_replace($languageArray, "", $base);
    
    		if ( $pagenum > 1 && strpos($request, '?lang=') !== FALSE) {
    			$result = $base . $request . "&paged=" . $pagenum;
    		}
    		else if ($pagenum > 1) {
    			$result = add_query_arg( 'paged', $pagenum, $base . $request );
    		} else {
    			$result = $base . $request;
    		}
    	} else {
    		$qs_regex = '|\?.*?$|';
    		preg_match( $qs_regex, $request, $qs_match );
    
    		if ( !empty( $qs_match[0] ) ) {
    			$query_string = $qs_match[0];
    			$request = preg_replace( $qs_regex, '', $request );
    		} else {
    			$query_string = '';
    		}
    
    		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
    		$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request);
    		$request = ltrim($request, '/');
    
    		$base = trailingslashit( get_bloginfo( 'url' ) );
    		if (strpos($base, '?lang=') !== FALSE)
    			$base = str_replace($languageArray, "", $base);
    
    		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
    			$base .= $wp_rewrite->index . '/';
    
    		if ( $pagenum > 1 ) {
    			$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
    		}
    
    		$result = $base . $request . $query_string;
    	}
    
    	/**
    	 * Filter the page number link for the current request.
    	 *
    	 * @since 2.5.0
    	 *
    	 * @param string $result The page number link.
    	 */
    	//$result = apply_filters( 'get_pagenum_link', $result );
    
    	if ( $escape )
    		return esc_url( $result );
    	else
    		return esc_url_raw( $result );
    }

    Hope it helps someone! ??

Viewing 1 replies (of 1 total)