• Resolved nikixiaoyou

    (@nikixiaoyou)


    Hi!

    It’s my first time posting on this forum, hopefully I won’t break any rule!
    We have problems on our website since the last WordPress update. More specifically, when switching to French language (button is in the upper right corner), any post on the main page that is shown after the 10th one will be displayed in English (instead of French). The 10th post will also be shown twice, once in French, and then in English right after. This is correlated to the “Blog pages show at most” setting. If we change this setting to 100, for example, we no longer have this problem (we only have 77 French posts), however the site takes forever to load, which is far from ideal.
    I’m thinking there’s a problem with the load_page(page n) function in the Horizontall theme (I have posted on their forum but I think it’s no longer maintained) which doesn’t consider the language properly.
    We’re using wpml for translation. We have already contacted them, but they think the issue isn’t on their side.

    Thank you in advance for your help!

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)
  • The topic ‘Post loading bug in second language past the max number of reads’ is closed to new replies.