【问题标题】:wordpress WPML advanced fields relationshipwordpress WPML 高级字段关系
【发布时间】:2013-07-01 09:01:28
【问题描述】:

我正在制作一个使用高级自定义字段关系插件的多语言网站。我正在读出雇主,如果我用网站的母语读出它们,我的问题为零,但是当我尝试用另一种语言读出它们时,我得到一个空数组。 你们有谁知道我能做什么吗?

<?php
    $field = get_post_meta( get_the_id() );
    $posts = get_field('field_81');
    echo '<!--';
        echo 'test ';
        var_dump( $field );
        var_dump( $posts );
    echo '-->';
?>

<?php
    if (ICL_LANGUAGE_CODE == 'en'):
?>

<?php
    $fields = $field['medewerkers'];
?>

<?php
    $posts = $fields;
?>

<?php
    endif;
?>  

<?php
   if ($posts):
?>

<?php
       if (ICL_LANGUAGE_CODE == 'nl'):
?>
           <h3 class="titelmedewerkers">Medewerkers</h3>    
           <?php
                elseif (ICL_LANGUAGE_CODE == 'en'):
           ?>
           <h3 class="titelmedewerkers">Employees</h3>
           <?php
                elseif (ICL_LANGUAGE_CODE == 'fr'):
           ?>
           <h3 class="titelmedewerkers">Employes</h3>   
           <?php
                else:
           ?>
            <h3 class="titelmedewerkers">Medewerkers</h3>   
           <?php
                endif;
           ?>       
            <ul class="medewerkers">
            <?php
                       foreach ($posts as $post): // variable must be called $post (IMPORTANT) 
                    ?>
            <?php
                          setup_postdata($post);
                    ?>
                  <li class="shadow">
                <strong><?php
                                 the_title();
                            ?></strong><br />
                <?php
                                 if (get_field('foto')):
                            ?>
                <?php
                                    $attachment_id = get_field('foto');
                                    $size          = "medium";
                                    $image         = wp_get_attachment_image_src($attachment_id, $size);
?>
                    <img src="<?php echo $image[0]; ?>" alt="<?php  the_title(); ?>" /><br />
                <?php
                                 endif;
                             ?>
                <?php
                                 if (get_field('afdeling')):
                            ?>
                <?php
                                    the_field('afdeling');
                            ?><br />
                <?php
                                    endif;
                            ?>
                <?php
                                    if (get_field('titel')):
                            ?>
                    <?php
                                    the_field('titel');
                            ?><br />
                <?php
                                    endif;
                            ?>
                <?php
                                    if (get_field('tel')):
                            ?>
             <a href="tel:<?php the_field('tel'); ?>"><?php the_field('tel'); ?></a><br />
                <?php
                     endif;
                ?>
            </li>
        <?php
                endforeach;
            ?>
    <?php
        wp_reset_postdata();
    ?>
    </ul> 
<?php
    endif;
?>
<?php
      wp_reset_postdata();
?>

【问题讨论】:

  • $posts var 已序列化,在此之前尝试unserialize($posts)
  • 为什么有这么多的打开和关闭php标签?

标签: php wordpress foreach


【解决方案1】:

这部分:

<?php
if (ICL_LANGUAGE_CODE == 'en'):
?>
<?php
 $fields = $field['medewerkers'];
?>
<?php
 $posts = $fields;
?>
        <?php
endif;
?>  

仅在en 时创建 $post,这并不奇怪您没有其他语言版本

【讨论】:

  • 我知道,这就是我想要做的,它没有显示我英语,只有荷兰语
  • 所以如果你使用非荷兰语 var_dump( $field );var_dump( $posts ); 返回空数组?
猜你喜欢
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 2012-08-10
  • 2015-01-21
  • 2017-05-01
  • 1970-01-01
  • 2013-09-10
  • 2018-06-07
相关资源
最近更新 更多