【问题标题】:How to set Gravatar as background image in Wordpress? [duplicate]如何在 Wordpress 中将 Gravatar 设置为背景图像? [复制]
【发布时间】:2016-02-29 13:42:58
【问题描述】:

我正在开发一个自定义 WordPress 主题,根据设计要求,我必须在图像背景中设置作者 Gravatar。

我尝试使用get_avatar_url()wp_get_attachment_image_src 如下,但无法实现:

PHP 内嵌代码:

<?php $thumb = wp_get_attachment_image_src(get_avatar_url($post->ID), '80'); ?>

<div class="author" style="background-image: url('<?php echo $thumb[0]; ?>')"></div>

CSS:

.author {
width:120px;
height:120px;
background: no-repeat center;
}

我如何做到这一点?

【问题讨论】:

    标签: php css wordpress avatar gravatar


    【解决方案1】:

    我在这里找到了答案 (https://stackoverflow.com/a/29860844/3725816):

    function my_gravatar_url() { // Get user email
    $user_email = get_the_author_meta('user_email');
    // Convert email into md5 hash and set image size to 80 px
    $user_gravatar_url = 'http://www.gravatar.com/avatar/' . md5($user_email) . '?s=120';
    echo $user_gravatar_url;
    }
    
    
    <div class="author" style="background: url('<?php echo my_gravatar_url(); ?>') center center no-repeat; top: 50%; left: 50%;">
    </div>           
    

    【讨论】:

      【解决方案2】:

      这是解决方案。它在我的网站上运行良好。

      <div 
          style = "background-image: 
                      url('<?php echo get_avatar_url(get_the_author_meta('ID'), array("size"=>450)); ?>'); 
                  height: 450px; 
                  width:450px">
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-07
        • 2014-06-23
        • 1970-01-01
        • 2014-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        相关资源
        最近更新 更多