2016-02-29 2 views
1

Я работаю над пользовательской темой WordPress и в соответствии с требованиями к дизайну, я должен установить Author Gravatar на фоне изображения.Как установить Gravatar в качестве фонового изображения в Wordpress?

Я попытался с помощью 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; 
} 

Как этого добиться ?

ответ

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>