WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] JavaScript not loading when switching languages (3 posts)

  1. KeenanPayne
    Member
    Posted 1 year ago #

    Hello,

    I was working on a website for a client (http://www.infiniacorp.com) and am using the Polylang plugin to switch between English, Spanish, and Italian.

    The homepage pulls in static content from pages and as you can see on the English and Spanish versions, the drop-down menu and background slider work fine. However, on the Italian version, it does not.

    Here is the custom PHP I am using to pull in the content from pages, and check which language the site is using:

    <?php
    		$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    		if (false !== strpos($url,'es')):
    			$page_id = 788;
    		elseif (false !== strpos($url,'it')):
    			$page_id = 1031;
    		else:
    			$page_id = 784;
    		endif;
    	?>
    
    	<?php
    		$page_data = get_page( $page_id );
    		echo apply_filters('the_content', $page_data->post_content);
    	?>

    This just checks what language code is in the URL, and sets the correct page ID for the given language. This code worked fine with just English and Spanish, but when I added Italian, it didn't work completely.

    Just to give you a little more background on my custom code, the background is supposed to be an image slider (this is not a theme I developed myself) so in the backend of WordPress I created multiple sliders for each language, and used this code to display them:

    <?php
    $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if (false !== strpos($url,'es')): //If spanish
    	$featured_page_language = 808;
    elseif (false !== strpos($url,'it')): //If italian
    	$featured_page_language = 1033;
    else: //If English
    	$featured_page_language = $featured_page;
    endif;
    ?>

    Very similar to the code above. It stores the ID of the slider and should display it, except it just doesn't work for Italian.

    All of the inner pages and everything work fine, it's just this homepage that's not doing it.

    I would appreciate any help in fixing this, and thank you for developing such a great plugin. I would gladly shoot you over a donation if you could help me resolve this.

    Best,
    Keenan

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    I would gladly shoot you over a donation if you could help me resolve this

    The support on this forum is free. Donations to plugin authors should not be done in exchange of any support. See: http://codex.wordpress.org/Forum_Welcome#Offering_to_Pay

    To your problem now. For me the Italian page loads correctly (It looks like the content is in Italian). But the slideshow does not load correctly. Looking at the source code of your English page, pictures are defined in your slideshow (I replaced all urls by ...):

    slides 					:  	[			// Slideshow Images
    {image : ...}		],

    when there is none for the Italian page:

    slides 					:  	[			// Slideshow Images
    		],

    So I would rather look at the way you defined the Italian pictures for your slideshow.

    Moreover, I believe that your tests are not very robust:

    if (false !== strpos($url,'/es/')):

    would be better.

    Or you can let Polylang do the job itself (if pages are translations of each other), suppress the tests and call:

    $page_data = function_exists('pll_get_post') ? get_page(pll_get_post(784)) : get_page( 784 );
  3. KeenanPayne
    Member
    Posted 1 year ago #

    Chouby,

    Thank you very much for your help. I looked in the source and saw that the images weren't being pulled in, and I have no idea why. I re-created the Italian version and all of the posts and content, but I still couldn't get it to work. I had to hack the theme and do this:

    slides 					:  	[			// Slideshow Images
    
    		<?php
    			if (false !== strpos($url,'/it/')): //If italian
    				echo "{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_009.jpg', title : '<div class=\"slideshow_title\">Tecnologia Solare d’avanguardia </div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_009-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_013.jpg', title : '<div class=\"slideshow_title\">Progetti su vasta scala e località remote.</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_013-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_008.jpg', title : '<div class=\"slideshow_title\">Alto rendimento del motore di Stirling</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_008-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_003.jpg', title : '<div class=\"slideshow_title\">Cambiando il modo in cui il mondo utilizza energia</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_003-60x60.jpg', url : ''},{image : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_004.jpg', title : '<div class=\"slideshow_title\">Motore e potenza aziendale nelle persone</div>', thumb : 'http://www.infiniacorp.com/wp-content/uploads/2012/06/infinia_slideshow_004-60x60.jpg', url : ''}	";
    			endif;

    In order to get any slides to show up. I mean I guess it works. Thanks for the heads up on my language tests, I got those changed to make them a little more robust.

    Best,
    Keenan

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic