简体   繁体   English

获取Wordpress作者图像网址问题

[英]Getting wordpress author image url issue

I am having trouble understanding why I can't get the author url to work. 我无法理解为什么我无法使作者网址正常工作。 I am getting the gravatar uri but the image is not showing. 我正在获取图像uri,但图像未显示。

Here is what is being displayed in the html code: 以下是html代码中显示的内容:

<div class="authorBackgroundImg slick-slide" style="background: url(&quot;http://1.gravatar.com/avatar/d098d4e8?s=96&amp;d=mm&amp;r=g&quot;) 0% 0% / cover no-repeat; height: 445px; position: relative; width: 217px;" data-slick-index="5" aria-hidden="true" tabindex="-1" role="option" aria-describedby="slick-slide05">

Here is what the php code looks like to retrieve the avatar url: 这是php代码用来检索化身网址的样子:

$profileImgUrl = get_avatar_url( $userId, '500' );

Here is the query for the wordpress database: 这是对wordpress数据库的查询:

$queryAuthorVals = "
                SELECT DISTINCT {$wpdb->prefix}users.display_name, {$wpdb->prefix}users.ID, {$wpdb->prefix}posts.post_author
                FROM {$wpdb->prefix}users, {$wpdb->prefix}posts
                LEFT JOIN {$wpdb->prefix}term_relationships rel ON rel.object_id = {$wpdb->prefix}posts.ID
                LEFT JOIN {$wpdb->prefix}term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id
                LEFT JOIN {$wpdb->prefix}terms t ON t.term_id = tax.term_id
                WHERE {$wpdb->prefix}posts.post_author = {$wpdb->prefix}users.ID
                AND {$wpdb->prefix}posts.post_type = 'post'
                ORDER BY {$wpdb->prefix}users.display_name ASC
            ";

            $postAuthors = $wpdb->get_results($queryAuthorVals, OBJECT);

"Note" I have removed part of the id from the users avatar url ' http://1.gravatar.com/avatar/d098d4e8?s=96&d=mm&r=g ' but it shows the avatar when I put the url in the browser. “注意”我已从用户头像网址' http://1.gravatar.com/avatar/d098d4e8?s=96&d=mm&r=g '中删除了部分ID,但当我将网址放入浏览器。 Also I can display the <img /> element with get_avatar( $userId, '500' ); 我也可以使用get_avatar( $userId, '500' );显示<img />元素get_avatar( $userId, '500' ); but this is not what I want to do. 但这不是我想要的。

Anyone know how to fix this, I can't seem to find a solution on google. 任何人都知道如何解决此问题,我似乎无法在Google上找到解决方案。

Cheers 干杯

OK so I figured it out, because I'm using the ultimate member plugin I have got it to work by using the ultimate member functions 好的,所以我想通了,因为我使用的是Ultimate Member插件,所以我可以通过使用Ultimate Member函数来使其正常工作

$ultimatemember->user->set( $userId );//set the user id
$userAvatar = um_get_avatar_uri( um_profile('profile_photo'), 400 );//get the user avatar based on the current user id.

I tried this earlier but didn't use the set user function $ultimatemember->user->set( $userId ); 我较早尝试过,但是没有使用set用户函数$ultimatemember->user->set( $userId ); so it was grabbing my avatar for each author image as I'm building a custom authors slider. 因此在构建自定义作者滑块时,它抓住了每个作者图像的头像。

Hope this helps someone else :) 希望这对其他人有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM