Skip Navigation

[Resolved] Set current language as condition in Views

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Shane 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1673265

Dear Sir/Madam,

I manually upload the document to server via ftp, I name the file as xxxx_e.pdf and xxxx_c.pdf for both language English and Traditional Chinese respectively. How can I get the current language from the page and define the condition

[condition lang=en]
         <a target="_blank" href="/press/[types field='press_pdf' output='raw'][/types]_e.pdf">[wpv-post-title]</a>
[/condition]
[condition lang!=en]
         <a target="_blank" href="/press/[types field='press_pdf' output='raw'][/types]_c.pdf">[wpv-post-title]</a>
[/condition]
#1673973

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

Thank you for getting in touch.

Try using this custom shortcode below.


// Add Shortcode
function cust_get_current_language() {

	if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
	  return ICL_LANGUAGE_CODE;
	}

}
add_shortcode( 'cust_get_current_language', 'cust_get_current_language' );

Add this to your custom code section by going to Toolset -> Settings -> Custom Code.

Then you need to add the custom shortcode name to the views 3rd party shortcode arguments in Toolset->Settings -> Frontend.

Finally you should be able to do this.

[wpv-conditional if="('[cust_get_current_language]' eq 'cn']
         <a target="_blank" href="/press/[types field='press_pdf' output='raw'][/types]_e.pdf">[wpv-post-title]</a>
[/wpv-conditional]

Please let me know if this helps.
Thanks,
Shane

#1674181

Dear Shane,

Thanks for your suggested coding, I will test it and keep you update.

#1675017

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

Is there an update on this one ?

Were you able to resolve the issue with the code I sent ?

Thanks,
Shane

#1676429

Dear Shane

May I know whether it is same as adding script in functions.php? I prefer to add code to functions.php. I add the code to functions.php what should I add from the Toolset Settings > Front-end Content? Only the Third-party shortcode arguments or Functions inside conditional evaluations but no Third-party shortcode inside conditional evaluations.

I refer to the article from https://toolset.com/forums/topic/problem-with-condtional-output-for-custom-function/

I found it use Third-party shortcode inside conditional evaluations, is it not support anymore?

// Add Shortcode
function cust_get_current_language() {
 
    if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
      return ICL_LANGUAGE_CODE;
    }
 
}
add_shortcode( 'cust_get_current_language', 'cust_get_current_language' );
#1676527

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kelvin,

May I know whether it is same as adding script in functions.php?

Yes it is the same as adding it to the functions.php file. Remember if you add it to the toolset custom code section you will need to click the activate link.

Only the Third-party shortcode arguments or Functions inside conditional evaluations but no Third-party shortcode inside conditional evaluations.

You will need to add the shortcode name to the Third Party shortcode argument box i.e add "cust_get_current_language"

Third party shortcode arguments is still supported.

Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.