Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

fokkezb on "[Plugin: Polylang] Showing default language post if no translation is available"

$
0
0

The solution above assumes that all posts at least have a version in the default language. However, this might not always be the case. For example; I have a blog where some posts are in English only, others in Dutch only and some in both. On the English blog I want to show English only, but on the Dutch blog I want to show English + Dutch.

For this I use the following code. For the Dutch blog it selects both English and Dutch blogs and then just skips any English post for which it also finds a translation.

<?
global $wp_query;
$language = pll_current_language();
query_posts(array_merge($wp_query->query, array('post_type' => 'post', 'lang' => ($language == 'en' ? 'en' : 'en,nl'))));
?>

<?php if (have_posts()) : $countposts = 0; while (have_posts()) : the_post(); ?>	

	<?php
	global $post;
	if ($language == 'nl' && ($post_id = pll_get_post($post->ID, pll_current_language())) && $post_id != $post->ID && ($post_nl = get_post($post_id)) && $post_nl->post_status == 'published') {
		continue;
	}
	?>

	YOUR LOOP MARKUP HERE

<? endif: ?>

Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>