0

I´m display a slider that get´s the images from custom field, now I need that the slider shows different images depending on the language (es - ca):

This is the code of the slider:

        <a href="<?php the_field('slider_home_1_enlace') ?>">
            <img src="<?php the_field('slider_home_1'); ?>">
        </a>

So I´m creating a conditional tag to load images depending of the language of qtranslate plugin:

        <?php
        _e('<!--:es-->
                <a href="<?php the_field('slider_home_1_enlace') ?>">
                    <img src="<?php <the_field('slider_home_1'); ?>">
                </a>
            <!--:-->
            <!--:ca-->
                <a href="<?php the_field('slider_home_1_enlace_ca') ?>">
                    <img src="<?php the_field('slider_home_1_ca'); ?>">
                </a>
            <!--:-->');
        ?>

I´m a php begginer so I see the problem maybe that the php is inside another php, because this way its not working, if i just put text between tags it works properly for the language.

Any ideas how to syntax this?

1
  • you should complete each php tag.before writing new php tag lik <?php code here ?> Commented Nov 9, 2012 at 11:41

4 Answers 4

3

You need to check language first, using if - else

detect the language and store it to the variable named $language and then check the condition as below.

<?php
if(qtrans_getLanguage()=="es"){
?>
  <a href="<?php the_field('slider_home_1_enlace'); ?>">
      <img src="<?php the_field('slider_home_1'); ?>">
  </a>
<?php
} else if(qtrans_getLanguage()=="ca"){
?>
  <a href="<?php the_field('slider_home_1_enlace_ca'); ?>">
      <img src="<?php the_field('slider_home_1_ca'); ?>">
  </a>
<?php
}
?>
Sign up to request clarification or add additional context in comments.

5 Comments

@diego how you are detecting the language selected? I mean how would u know which language to show?
i'm just using qtranslate and with this it detects the language "<!--:es-->" i'm not using anymore
if you are using qtranslate then check the if condition like this if(qtrans_getLanguage()=='en')
@diego - check the edited answer !! i am editing now !! give it a try as i am not a wordpress user and haven't used qtranslate before. But still try this.
@diego - My pleasure !! Enjoy !! :)
0

You can't have php-tags inside each other.

Use basic string concatenation to combine your strings: http://php.net/manual/en/language.operators.string.php

Comments

0

You can't use it that way. Compare: (I guess that the_field() returns the string ;))

<a href="'.the_field("slider_home_1_enlace").'">
    <img src="'.the_field("slider_home_1").'" />
</a>

There are multiple mistakes. At first, you can't use the

'.(your things here).'

Second, theres a < in your fourth line and you forget to close your img-tag.

4 Comments

this doesn´t gives error, but the problem is that it shows the url of the image instead of displaying it :S do you know why?
Are you sure that the path is correct? Most browsers display the path, if the image doesn't exist. Note: I had a typo in my code. Try again.
Hm. The img-tag is correct; if the path is too, I don't know. Please check the resulting html!
the resulting html is that it displays the full text plain of the "a" and the "img", not with the tags
0

First, install the qTranslate Wordpress plugin.

Then, you can try this:

<?php

    $slider_img_fields_langs = array(
        '',
        'ca',
        'es',
    );

    $lang = qtrans_getLanguage();
    if( !in_array( $lang, $slider_img_fields_langs ) );
        $lang = '';

    echo '
<a href="' . the_field( 'slider_home_1_enlace' . $lang ) . '">
    <img src="' . the_field( 'slider_home_1' . $lang ) . '">
</a>';

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.