【问题标题】:Display all users/authors in wordpress template在 wordpress 模板中显示所有用户/作者
【发布时间】: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">[&nbsp;<?php echo $user->display_name; ?>&nbsp;]</h2>

【问题讨论】:

    标签: php wordpress advanced-custom-fields user-profile


    【解决方案1】:

    您应该像这样在get_the_author_meta 中添加用户 ID:

    $user_id = $user->ID;
    $publisher_photo = get_the_author_meta('author_header', $user_id);
    

    请确保您将在循环中添加此代码,因此每次不同用户的 user_id 都会不同。

    问候, 斯塔尼米尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      • 2016-08-14
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多