• Hi, WP users!

    I am really fond of WordPress and have been using it for a year now. The available plug-ins and support is great. However, I am struggling now with WPML plug-in and a recent works code (you can find it here – https://www.agent-seo.com/wordpress/recent-posts-with-thumbnails-in-wordpress-without-a-plugin/).

    I am creating a multilingual site. I have managed to put everything to work, however if I translate my posts, both the original and translated versions appear on my page. I am not good at PHP, so I look forward to your help.

    If the current language is X, the posts from category X1 are shown.
    If the current language is Y, the posts from category Y1 are shown.

    This should make it pretty clear what I expect. I tried to put the function clang to change the category ID in get_posts function, but it did not work.

    Any ideas?

    Regards,
    Marten

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mlauri

    (@mlauri)

    This should be the piece of code which calls the posts and should be edited.

    <?php $postslist = get_posts('numberposts=50&order=DESC'); foreach ($postslist as $post) 
    
    : setup_postdata($post); ?>
    Thread Starter mlauri

    (@mlauri)

    Although nobody replied, I found the solution with a help of my friend. If anyone of you has the same issue, then you can use different category for each language. For example, the language X is ‘6’ and language Y is ‘5’. So, in the get_posts function you simply add a function which changes the category id according to the current language. We used
    category=' . loeKeeleNumber()

    In the functions.php file you simply add the following rows:

    function loeKeeleNumber()
    {
         if (ICL_LANGUAGE_CODE=='et')
            return 6; //language X
         elseif (ICL_LANGUAGE_CODE=='fi')
               return 5; //language Y
         else
                return 0; //default value
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WPML Multilingual CMS] Translated Posts Duplicated on Recent Posts page’ is closed to new replies.