Jump to content

Exclude user's current language (from list)


IkBenBen
 Share

Recommended Posts

Sorry if this has been asked before but had no luck finding an answer so far on the forums, so here I go!

I made a list that shows all the languages which works perfectly. My question now is, how do I exclude the (user's) language that's currently active from the list?

For example, I'm viewing the English site, how do I exclude English from the list...

  • Dutch
  • English
  • German

... so it only shows...

  • Dutch
  • German

... and when viewing the Dutch site excluding Dutch, when viewing the German site excluding German.. etc..

This is my code:

<?php 
	foreach($languages as $language) {
		if(!$page->viewable($language)) continue; // check if page not published for this language
		$url = wire('page')->localUrl($language);
		$title = $language->getUnformatted('title')->getLanguagevalue($language->id);
		$name = $language->get('language_name');
		$location = $config->urls->templates;
		echo "<li>$title</a></li>";
	}
?>

Just started with Processwire so forgive me for asking a stupid question!  :lol:

Thanks in advance!

Link to comment
Share on other sites

Hi Bueno,

Try this 

foreach($languages as $language) {
	if(wire('user')->language->id == $language->id) continue; // skip current language
	if(!$page->viewable($language)) continue; // check if page not published for this language
	$url = wire('page')->localUrl($language);
	$title = $language->getUnformatted('title')->getLanguagevalue($language->id);
	$name = $language->get('language_name');
	$location = $config->urls->templates;
	echo "<li>$title</a></li>";
}
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...