1

我想创建一个包含所有用户配置文件的页面,但我只想显示他们在其用户配置文件的高级自定义字段中定义的图像。

我试图做这样的事情:

<?php if (is_page(9)){ ?>   
<section class="pageContent contentWidth">
<ul class="profilePictures">
<?php
    $blogusers = get_users('orderby=nicename&role=subscriber');
    foreach ($blogusers as $user) {
        echo '<li><div class="image_wrapper"><img class="profile1" src="';
        $user->the_field('profilbild');
        echo '"/></div><img class="profile2 hoverShow" src="';
        $user->the_field('funbild');
        echo '"/><div class="imageOverlay"><p>';
        $user->the_field('nickname');
        echo '</p></div></li>';
    }
?>
</ul>
</section>
<?php } ?>

但我在前端得到的只是:

<section class="pageContent contentWidth">
<ul class="profilePictures">
<li><div class="image_wrapper"><img class="profile1" src="

然后结束。

编辑:错误是:

致命错误:在第 208 行的 .../index.php 中调用未定义的方法 WP_User::the_field()

这是线

$user->the_field('profilbild');

所以我似乎不能从那里调用这个方法。但是我该怎么做呢?

Edit2:所以我找到了方法未找到错误的解决方案。我现在只是在回显这些字段的简码:

echo '<li><div class="image_wrapper"><img class="profile1" src="
[acf field="profilbild"]
"/></div><img class="profile2 hoverShow" src="
[acf field="funbild"]
"/><div class="imageOverlay"><p>
[acf field="nickname"]
</p></div></li>';

但它无法找到我认为的正确用户。ACF 不知道该去找哪个用户。

对此有什么解决方案?

4

1 回答 1

1

解决方案如下:

$image1 = get_field('profilbild', $user);
$image2 = get_field('funbild', $user);
$name = get_field('nickname', $user);
echo '<li><div class="image_wrapper"><img class="profile1" src="';
echo $image1['url'];
echo '"/></div><img class="profile2 hoverShow" src="';
echo $image2['url'];
echo '"/><div class="imageOverlay"><p>';
echo "$name";
echo '</p></div></li>';

我希望这个能帮上忙!

于 2014-01-09T01:37:18.937 回答