【发布时间】:2016-07-11 18:00:57
【问题描述】:
我正在尝试使用高级自定义字段在自定义页面模板中显示我的所有作者/用户。我正在使用以下代码来显示他们从名为author_header 的 acf 图像字段中获取的个人资料照片。我按以下方式将用户放入无序列表中。
<div class="author">
<ul>
<li>
<?php
$publisher_photo = get_the_author_meta('author_header');
$image_src = wp_get_attachment_image_src($publisher_photo);
echo '<img src="'. $image_src[0] .'" />';
?>
</li>
</ul>
</div>
我面临的问题是所有用户都获得了我的个人资料照片。我希望能够抓住他们上传到author_header 字段的那些。
我也试过这个修改后的代码,但是 img src 没有出现。
<?php
$field_name = "author_header";
$post_id = "user_{$user_id}";
$publisher_photo = get_field($field_name, $post_id);
$image_src = wp_get_attachment_image_src($publisher_photo);
echo '<img src="'. $image_src[0] .'" />';
?>
我确实让他们的所有名字都正确显示在以下无序列表中。
<h2 class="authorName">[ <?php echo $user->display_name; ?> ]</h2>
【问题讨论】:
标签: php wordpress advanced-custom-fields user-profile