Hello,
I have created a View with a Content Template. I am using Visual Composure to design the layout and all is working pretty well. I am using the View for a job listing. The Job listing is in 4 Languages and so my end goal is you see the Job Title, an excerpt of the Job description. Then underneath this is the option to view the Job Description in the other languages.
I have been able to add the Language Switcher, but I notice when I click the Language I want to read the post in, I am only taken to the Home page of that language.
How can I click the Flag and I am taken to the full page of the listing from that language?
Site is in development so credentials to login:
vianova
via2019
hidden link
Scroll down to Join Us
For example, if you click NOW HIRING: ACCOUNTANT language for French, it should take you here: hidden link
How can I create an option that could do this?
Thank you for your time.
Hi, there's nothing exactly like this built in to Toolset or WPML, because the Language Switcher is designed for use on single posts and not search results. Based on the code sample in the Custom Language Switcher documentation, I can provide you a custom shortcode that will do something similar. Here's the documentation link:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/#language-selector-with-flags-only
Here's the code you can add to your child theme's functions.php file, or to a new Code Snippet in Toolset > Settings > Custom Code:
function show_language_selector_flags(){
$out = '';
if( !function_exists('icl_get_languages'))
return $out;
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active'])
$out .= '<a href="'.$l['url'].'">';
$out .= '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
if(!$l['active'])
$out .= '</a>';
}
}
return $out;
}
add_shortcode( 'ts-show-language-selector-flags', 'show_language_selector_flags');
Then in your View's loop or loop template:
<div class="ts_flags_language_selector">[ts-show-language-selector-flags][/ts-show-language-selector-flags]</div>
And in your View's Loop Editor CSS panel:
.ts_flags_language_selector img{
margin:1px;
border:1px solid #333;
}
Christian, you guys are amazing at how fast and helpful you are!
Ok, so I set this up but I for the French page to test but I see it's only redirecting to the HOME page still and not the Custom Post Type that needs to be translated.
hidden link
Here is my child theme currently: https://pastebin.com/cmfJ8qWt
Okay I see the issue. What if the language translation does not exist - should the flag appear without a link, or should the flag not appear?