I am trying to show post author avatars in the home page of my wordpress site , now it is showing a common icon for all authors using the following code

<article>
        <header>
        <div class="date"><?php the_time('M') ?><br /><span class="day"><?php the_time('j') ?></span><br /><?php the_time('Y') ?></div>
        <div class="category"><?php the_category(' // ') ?></div>
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> 
        </header>
        <?php if(of_get_option("alltuts_posts_layout")==0) { ?>
        <div class="postThumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a></div>
        <div class="textPreview">
            <?php the_excerpt(); ?>
        </div>
        <?php } else { ?>
            <?php the_content(''); ?>
        <?php } ?>
        <footer>
            <a href="<?php the_permalink() ?>" class="more-link"><?php _e('Continue Reading ', 'site5framework'); ?>&raquo;</a>
            <div class="metaRight">
                <img src="<?php bloginfo('template_directory'); ?>/images/ico_author.png" alt="<?php _e('Author', 'site5framework'); ?>"/> <?php _e('An article by ', 'site5framework'); ?> <?php the_author_link(); ?>
                <img src="<?php bloginfo('template_directory'); ?>/images/ico_comments.png" alt="<?php _e('Comments', 'site5framework'); ?>"/> <?php comments_popup_link(__("No Comments", "site5framework"),__("1 Comment", "site5framework"),__("% Comments", "site5framework") );?>
            </div>
        </footer>
    </article>

Please see the running code here

Thanks in advance

有帮助吗?

解决方案

The easiest way to show Wordpress author avatars would be to use the service provided by Gravatar (http://www.gravatar.com/).

Wordpress provides a function called get_avatar that allows you to fetch the avatar for the supplied user or email address.

Here's an example on what you'd need to change:

Replace:

<img src="<?php bloginfo('template_directory'); ?>/images/ico_author.png" alt="<?php _e('Author', 'site5framework'); ?>"/>

With:

<?php echo get_avatar(get_the_author_meta('user_email'), 32);?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top