• Hello,

    I have one problem I’m making a multi language website for 7 languages, for each language there is a post created in the backend so that can be easily edited. In template files there is an IF function to display correct post when there is a language switch. I have managed to set it up to work for 3 languages, does anyone have an idea how to extend it to 7 languages?

    Sample code:

    		<?php $currentlang = get_bloginfo('language');
    		if($currentlang=="sl-SI"):?>
    			<?php
    				$post_id = 93;
    				$queried_post = get_post($post_id);
    				$content = $queried_post->post_content;
    				$content = apply_filters('the_content', $content);
    				$content = str_replace(']]>', ']]>', $content);
    				echo $content;
    			?>
    		<?php elseif($currentlang=="en-GB"):?>
    			<?php
    				$post_id = 117;
    				$queried_post = get_post($post_id);
    				$content = $queried_post->post_content;
    				$content = apply_filters('the_content', $content);
    				$content = str_replace(']]>', ']]>', $content);
    				echo $content;
    			?>
    		<?php else: ?>
    			<?php
    				$post_id = 15;
    				$queried_post = get_post($post_id);
    				$content = $queried_post->post_content;
    				$content = apply_filters('the_content', $content);
    				$content = str_replace(']]>', ']]>', $content);
    				echo $content;
    			?>
    		<?php endif; ?>

    Best regards, Jurij

Viewing 2 replies - 1 through 2 (of 2 total)
  • In it’s simplest form, add in more elseif blocks:

    <?php elseif($currentlang=="ru_RU"):?>
    <?php
    	$post_id = 123;
    	$queried_post = get_post($post_id);
    	$content = $queried_post->post_content;
    	$content = apply_filters('the_content', $content);
    	$content = str_replace(']]>', ']]>', $content);
    	echo $content;
    ?>

    There’s also an opportunity to refactor to greatly reduce the duplicate code.

    Thread Starter spletnestoritve

    (@spletnestoritve)

    Thank you for your reply, I already tried to add another elseif block but I only get this echoed “a:0:{}” even if there is content in the post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use more than 3 languages in template files’ is closed to new replies.