web-dev-qa-db-fra.com

La fonction get_avatar de Wordpress ne fonctionne pas correctement

Mon code faisant cela, listant l'auteur qui a posté dans la catégorie actuelle. Mais la fonction get_avatar ne fonctionne pas correctement. J'utilise un plugin avatar local simple. Cela fonctionne author.php n'a pas de problème. Mais quand je l'utilise avec ce code, il liste les mêmes et les mauvaises images d'auteur (Ma dernière image d'auteur. . Vous pouvez regarder cette image )

Mon code:

<?php if (is_category()) {
$current_category = single_cat_title(“”, false);
$author_array = array();
$args = array(
'numberposts' => -1,
'category_name' => $current_category,
'orderby' => 'author',
'order' => 'ASC'
);
$cat_posts = get_posts($args);
foreach ($cat_posts as $cat_post) :
if (!in_array($cat_post->post_author,$author_array)) {
$author_array[] = $cat_post->post_author;
}
endforeach;
foreach ($author_array as $author) :
$auth = get_userdata($author)->display_name;
$autid= get_userdata($author)->ID;
echo get_avatar( get_the_author_email(), '32' );
echo "<a href='?author=";
echo $autid;
echo "'>";
echo $auth;
echo "</a>";
echo "<br />";
endforeach;
}?>
1
Genxer

Vous récupérez l'ID de l'auteur ici:

$autid= get_userdata($author)->ID;

Alors, pourquoi ne l'utilisez-vous pas pour obtenir l'avatar sur la ligne suivante?

echo get_avatar( get_the_author_email(), '32' );

get_avatar acceptera l'ID en tant que paramètre. Essayez ceci à la place:

echo get_avatar( $autid, '32' );

get_the-author_email est déconseillé de toute façon, donc même si cela fonctionnait, vous ne devriez pas l'utiliser.

0
s_ha_dum