Answer the question
In order to leave comments, you need to log in
How to substitute different pages in different languages?
How can I make it load different files on different pages?
<?php
$locale = get_locale();
if($locale == 'pl_PL'){
$download_text = 'Pobierz<br>katalog ';
$link_catalog = 'pll_get_post(2341)';
}else if($locale == 'lt_LT'){
$download_text = 'Parsisiųsti<br>katalogą';
$link_catalog = 'pll_get_post(2339)';
}else{
$download_text = 'Download<br>catalog';
$link_catalog = 'pll_get_post(14)';
}?>
<div class="catalog-file">
<a href="<?=get_field('catalog-file', pll_get_post(2341));?>" download title="catalog file">
<span><?=$download_text;?></span>
</a>
</div>
Answer the question
In order to leave comments, you need to log in
I wouldn't bother uploading catalog files in media at all. I doubt that someone will ever change them, so I would put them in the data folder in the theme as is, but you can always adapt the example below for yourself
if ( is_plugin_active( 'polylang/polylang.php' ) ) {
$locale = get_locale();
$data = [
'pl_PL' => [
'text' => 'Pobierz<br>katalog',
'file' => 'price-pl.xlsx',
],
'lt_LT' => [
'text' => 'Parsisiųsti<br>katalogą',
'file' => 'price-lt.xlsx',
],
'en_US' => [
'text' => 'Download<br>catalog',
'file' => 'price-en.xlsx',
],
];
echo '<div class="catalog-file">';
echo '<a href="' . get_stylesheet_directory_uri() . '/data/' . $data[$locale]['file'] . '" download="' . $data[$locale]['file'] . '">' . $data[$locale]['text'] . '</a>';
echo '</div>';
}
if ( file_exists( $file ) && filesize( $file ) > 0 ) {
// выводим, если существует
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question