Как отобразить многоязычные метки и значения из ACF и WPML на одном файле.php
Я работаю над многоязычным сайтом WordPress: animalfriendsvratsa.roxtest.nl У меня есть один файл шаблона, в котором я хотел бы отображать метки и значения на выбранном языке. Я пытался заставить его работать с get_field и get_field_object, но это, похоже, не работает.
Просто чтобы быть ясно: На английском я хотел бы сказать: Имя: Радость На болгарском языке это должно сказать: Имеется: Джой
Страница в настоящее время:
<?php
/**
* This template is for displaying the single pages for Adoptable Dogs
*
* @package Animal Friends Vratsa Theme
* @since Custom Theme 1.0
*/
?>
<?php get_header(); ?>
<div class="single-page">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="container">
<div class="row">
<!-- display pictures -->
<div class="col-md-6">
<div id="slider">
<a href="#" class="control_next">></a>
<a href="#" class="control_prev"><</a>
<ul>
<?php
$images = get_field('photos');
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<li><img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" /></li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<!-- display name -->
<?php
$field_name = "name_dog";
$field = get_field_object($field_name);
echo $field['label'] . ': ' . $field['value'];
?>
<?php
$name = get_field('name_dog'); ?>
<div class="col-md-4"><p class="single-data">Name:</p></div>
<div class="col-md-8"><p class="single-data"><?php echo $name; ?><br></p></div>
<?php
$field_name = "breed";
$field = get_field_object($field_name);
echo $field['label'] . ': ' . $field['value'];
?>
<!-- display breed -->
<?php $breed = get_field('breed'); ?>
<div class="col-md-4"><p class="single-data">Breed:</p></div>
<div class="col-md-8"><p class="single-data"><?php echo $breed; ?><br></p></div>
<!-- display age -->
<div class="col-md-4"><p class="single-data">Age:</p></div>
<div class="col-md-8"><p class="single-data">
<?php // Get terms for post
$terms = get_the_terms( $post->ID , 'age' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
print $term->name ;
// Get rid of the other data stored in the object, since it's not needed
unset($term);
} } ?>
<br></p></div>
<!-- display weight -->
<?php $weight = get_field('weight'); ?>
<div class="col-md-4"><p class="single-data">Weight:</p></div>
<div class="col-md-8"><p class="single-data"><?php echo $weight; ?><br></p></div><!--col-md-6-->
</div><!-- col-md-6 -->
<div class="col-md-6">
<!-- display sex -->
<div class="col-md-4"><p class="single-data">Sex:</p></div>
<div class="col-md-8"><p class="single-data">
<?php // Get terms for post
$terms = get_the_terms( $post->ID , 'sex' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
print $term->name ;
// Get rid of the other data stored in the object, since it's not needed
unset($term);
} } ?>
<br></p></div>
<!-- display size -->
<div class="col-md-4"><p class="single-data">Size:</p></div>
<div class="col-md-8"><p class="single-data">
<?php // Get terms for post
$terms = get_the_terms( $post->ID , 'size' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
print $term->name ;
// Get rid of the other data stored in the object, since it's not needed
unset($term);
} } ?>
<br></p></div>
<!-- display born in -->
<?php $born_in = get_field('born_in'); ?>
<div class="col-md-4"><p class="single-data">Born in:</p></div>
<div class="col-md-8"><p class="single-data"><?php echo $born_in; ?><br></p></div>
<!-- display organisation -->
<div class="col-md-4"><p class="single-data">Organisation:</p></div>
<div class="col-md-8"><p class="single-data">
<?php // Get terms for post
$terms = get_the_terms( $post->ID , 'organisation' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
print $term->name ;
// Get rid of the other data stored in the object, since it's not needed
unset($term);
} } ?>
<br></p></div>
</div><!--col-md-6-->
</div><!--row-->
<!-- display full description -->
<?php $full_description = get_field('full_description'); ?>
<div class="col-md-12"><p><?php echo $full_description; ?></p></div>
<div class="row">
<div class="col-md-6">
<?php $neutered = get_field('neutered'); ?>
<div class="col-md-6"><p class="single-data">Neutered:</p></div>
<div class="col-md-6"><p class="single-data">
<?php
if($neutered==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display vaccinated -->
<?php $vaccinated = get_field('vaccinated'); ?>
<div class="col-md-6"><p class="single-data">Vaccinated:</p></div>
<div class="col-md-6"><p class="single-data">
<?php
if($vaccinated==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display microchipped -->
<?php $microchipped = get_field('microchipped'); ?>
<div class="col-md-6"><p class="single-data">Microchipped:</p></div>
<div class="col-md-6"><p class="single-data">
<?php
if($microchipped==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display eu passport -->
<?php $eu_passport = get_field('eu_passport'); ?>
<div class="col-md-6"><p class="single-data">EU Passport:</p></div>
<div class="col-md-6"><p class="single-data">
<?php
if($eu_passport==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
</div><!--col-md-6-->
<div class="col-md-6">
<!-- display suitable for children -->
<?php $suitable_for_children = get_field('suitable_for_children'); ?>
<div class="col-md-10"><p class="single-data">Suitable for children:</p></div>
<div class="col-md-2"><p class="single-data">
<?php
if($suitable_for_children==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display suitable for elderly people -->
<?php $suitable_for_elderly_people = get_field('suitable_for_elderly_people'); ?>
<div class="col-md-10"><p class="single-data">Suitable for elderly people:</p></div>
<div class="col-md-2"><p class="single-data">
<?php
if($suitable_for_elderly_people==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display suitable for cats -->
<?php $suitable_for_cats = get_field('suitable_for_cats'); ?>
<div class="col-md-10"><p class="single-data">Suitable for other cats:</p></div>
<div class="col-md-2"><p class="single-data">
<?php
if($suitable_for_cats==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display suitable for other dogs -->
<?php $suitable_for_other_dogs = get_field('suitable_for_other_dogs'); ?>
<div class="col-md-10"><p class="single-data">Suitable for dogs:</p></div>
<div class="col-md-2"><p class="single-data">
<?php
if($suitable_for_other_dogs==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
<!-- display suitable for apartment -->
<?php $suitable_for_apartment = get_field('suitable_for_apartment'); ?>
<div class="col-md-10"><p class="single-data">Suitable for apartment:</p></div>
<div class="col-md-2"><p class="single-data">
<?php
if($suitable_for_apartment==1){
echo "Yes";
}else{
echo "No";
}?></p></div>
</div><!--col-md-6-->
</div><!--row-->
<div class="row share-row">
<div class="col-md-6 share-buttons">
<!-- Buttons are from https://simplesharebuttons.com/html-share-buttons/ -->
<!-- Social sharing -->
<p class="share-heading">Share <?php echo $name?> on social media</p>
<div class="social-share">
<!-- Facebook -->
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" target="_blank">
<img src="http://animalfriendsvratsa.roxtest.nl/wp-content/themes/Avada-Child-Theme/somacro/facebook.png" alt="Facebook" />
</a>
<!-- Twitter -->
<a href="https://twitter.com/share?url=<?php the_permalink(); ?>&text=Meet%20(and%20maybe%20even%20adopt)%20<?php echo $name?>&hashtags=adoptdontshop" target="_blank">
<img src="http://animalfriendsvratsa.roxtest.nl/wp-content/themes/Avada-Child-Theme/somacro/twitter.png" alt="Twitter" />
</a>
<!-- Google+ -->
<a href="https://plus.google.com/share?url=<?php the_permalink(); ?>" target="_blank">
<img src="http://animalfriendsvratsa.roxtest.nl/wp-content/themes/Avada-Child-Theme/somacro/google.png" alt="Google" />
</a>
<!-- Email -->
<a href="mailto:?Subject=Meet (and maybe even adopt) <?php echo $name?>&Body=I%20saw%20this%20and%20thought%20of%20you!%0D%0A<?php $short_description = get_field('short_description'); echo $short_description ?>%0D%0A
Meet%20<?php echo $name?>:%20<?php the_permalink(); ?>">
<img src="http://animalfriendsvratsa.roxtest.nl/wp-content/themes/Avada-Child-Theme/somacro/email.png" alt="Email" />
</a>
</div>
</div>
<div class="col-md-6">
<!-- Meet this dog email link button -->
<p class="single-button"><a href="mailto:info@animalfriendsvratsa.com?Subject=Adopting <?php echo $name?>&Body=Hi,%20I%20am%20interested%20in%20adopting%20<?php echo $name?>%20(<?php the_permalink(); ?>).%0D%0ACan%20you%20contact%20me%20for%20more%20info%20on%20adopting%20<?php echo $name?>?%0D%0AName:%0D%0AEmail%20address:%0D%0APhone%20number:%0D%0A">Adopt <?php echo $name?> </a><p>
</div>
</div><!-- row -->
</div><!--col-md-6-->
</div><!--row-->
</div><!--container-->
</div><!-- col-md-8 -->
</div><!-- row -->
</div><!-- container -->
</div><!-- -->
<?php get_footer(); ?>