• Hi

    I was wondering if it’s possible to do the followings:

    I loop through all my blog posts on archive.php to display the blog posts on a grid as a card with blog title, category name, etc. I was wondering if it’s possible to loop through the languages available for every single blog post as well. For example, on the card it says something like: Available in English, French, Spanish. If another blog is available in Spanish only, it would say something like Available in: Spanish

    Is it possible to do the same thing but on the single.php individual blog post page? For example, when you click to read a specific blog post, it says something like: This article is available in English, Spanish, Italian. If yes, is it also possible to add the hyperlink to the article in that language so if the user clicks on Spanish, it goes to the same blog post but in Spanish?

    Thank you and I hope they are clear.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yes It’s possible, I was looking for same thing, I found the pll_get_post_transaltions() function which I used in combination with pll_get_post to get the available languages. You would have to drop this in a relevant template file depending on your theme:

    $avilable_languages = pll_get_post_translations(get_the_ID());
    echo 'This post is available in: ';
    foreach($avilable_languages as $slug => $val) {
    	echo '<a href="' . esc_url( get_permalink( pll_get_post( $val, $slug ) ) ) . '">' . pll_get_post_language($val, 'name') . '</a>, ';
    }
    Thread Starter ashkanahmadi

    (@ashkanahmadi)

    Hi Luke.

    I just tested it and it worked beautifully. That’s amazing thank you so much.

    awesome, glad to hear it!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Possible to show the user the blog is available in what languages?’ is closed to new replies.