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

Chouby on "[Plugin: Polylang] Monthly archives"

$
0
0

Yes, Polylang works like this since the beginning for all archives (date, author, post type...). I preferred doing so because ckecking for the existence of archives in the other languages needs one query per language (and I am aware of sites using 7 languages!). I wanted to avoid this performance penalty. However, to be honest I did not measure it ;-) Up to now you are the first to ask about this:

You can add this in your functions.php or in a custom plugin:

add_filter('pll_language_link', 'check_archive_translation');
function check_archive_translation($url, $lang) {
	global $wp_query;
	$qv = $wp_query->query;

	if (is_month()) {
		$posts = get_posts(array(
			'lang'     => $lang,
			'year'     => $qv['year'],
			'monthnum' => $qv['monthnum'],
		));
		if (empty($posts))
			return null;
	}
	return $url;
}

Hopefully, it will do what you expect


Viewing all articles
Browse latest Browse all 11471

Trending Articles



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