WordPress.org

Ready to get started?Download WordPress

Forums

WP Bannerize
[resolved] WP Bannerize with qTranslate (6 posts)

  1. kevinj003
    Member
    Posted 3 years ago #

    I'm using bannerize to create a series of banners in the right column of my site. I also use qTranslate to produce the site in English, Spanish, German and Brazilian Portuguese, and I wondered if it is possible to have bannerize display a different version of each banner, based on the language selected by the user?

    Many thanks,

    Kevin

  2. gfazioli
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Kevin,
    I also use qTranslate.

    qTranslate allows you to use a special tag for the languages. For example in my site (italian and english) I write this simple function (put in functions.php):

    /**
     * Shorthand per qTranslate
     *
     * @param  $a
     * @param  $b
     * @return string|void
     */
    function __qt($a,$b) {
        return __("<!--:it-->$a<!--:--><!--:en-->$b<!--:-->");
    }

    In my theme page I use it:

    <?php __qt( "Ciao", "Hello") ?>

    So you could use the "group key" parameter to separate the different banner.

    1) Add your "English" banner in "adv-en" group
    2) Add your "Spanish" banner in "adv-es" group
    ...

    3) Use qtrans_getLanguage() for detect user language

    qtrans_getLanguage() return a string, for example "en" for english...

    4) So, call

    <?php
    wp_bannerize( "random=1&limit=10&group=adv-" . qtrans_getLanguage() );
    ?>

    or

    <?php
    $localizedGroup = "adv-" . qtrans_getLanguage();
    wp_bannerize( "random=1&limit=10&group=" . $localizedGroup ) );
    ?>

    I hope this help you

    regards
    GF

  3. kevinj003
    Member
    Posted 3 years ago #

    Hi GF,

    Thanks for your reply to my question. I'm glad to know that it can be done, but I'm a newbie to php coding, so I'm not fully sure I understand exactly what to add to which files. I'll have a play with this, and might ask for further help if I get stuck.

    Best wishes,

    Kevin

  4. gfazioli
    Member
    Plugin Author

    Posted 3 years ago #

    Hi kevin,
    Are you using the widget method for display the banners?

    If Yes, you have to switch to function method. For do this you have to edit your theme files.
    Find the sidebar.php in your folder theme.
    Insert a code similar to:

    <?php
    $localizedGroup = "adv-" . qtrans_getLanguage();
    wp_bannerize( "random=1&limit=10&group=" . $localizedGroup ) );
    ?>

    The code above can be insert in several positions, choose the best for you (try and change).
    You have to create a group of banner for each language, like: adv-en, adv-fr, etc...

    That's all

    If you have any question or problem, tell me or give me a temporary access to your server.

    Regards
    GF

  5. kevinj003
    Member
    Posted 3 years ago #

    Hi GF,

    I'm afraid I'm not getting very far with your advice - I think it might be a little beyong my knowledge level right now.

    I just inserted the following code inside the <div id="bannerWrapper"> </div> section at the bottom of sidebar-right.php in my theme:

    <?php
    	$localizedGroup = &quot;aark_sponsors_&quot; . qtrans_getLanguage();
    	wp_bannerize( &quot;random=1&limit=10&group=&quot; . $localizedGroup ) );
    	?>;

    However, this created the error "Parse error: syntax error, unexpected ';', expecting T_PAAMAYIM_NEKUDOTAYIM in /home/amphibia/public_html/wp-content/themes/amphibian-ark/sidebar-right.php on line 163" when I loaded the site, so I removed it again.

    I also added the following code at the top of functions.php in my theme:

    /**
     * Shorthand per qTranslate
     *
     * @param  $a
     * @param  $b
     * @param  $c
     * @param  $d
     * @return string|void
     */
    function __qtrans_getLanguage($a,$b) {
        return __("<!--:en-->$a<!--:--><!--:es-->$b<!--:--><!--:de-->$c<!--:--><!--:pt-->$d<!--:-->");
    }

    I currently have 4 jpg images, called aark_sponsors_en.jpg, aark_sponsors_es.jpg, aark_sponsors_de.jpg and aark_sponsors_pt.jpg All of the images are located in the /wp-content/uploads/2010/08 folder

    Should I be replacing the $a, $b etc. above with aark_sponsors_en.jpg, aark_sponsors_es.jpg etc?

    In wpBannerize I currently have a banner called AArk staff sponsors with the key right_sidebar, and it currently links to the aark_sponsors_en.jpg file

    However, the part of your instructions that I'n mot quite sure about is:

    So you could use the "group key" parameter to separate the different banner.

    1) Add your "English" banner in "adv-en" group
    2) Add your "Spanish" banner in "adv-es" group

    How do I use the group key parameter? If I switch from the widget method to the function method, will I need to have functions for all the banners I use? If so, I think this might become too problematic for me.

    I really appreciate your help and I'm happy to give you a temporary access to my server if that would help. If you email me at kevinj@amphibianark.org, I'll send you a temporary login.

    Thanks again,

    Kevin

  6. TiagoFonseca
    Member
    Posted 3 years ago #

    Hi GF,

    Just wanted to thank you, i'm using your function and it's really helpful.

    Regards,

    Tiago

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic