How to Add Author Information Blocks To Your Site

May 4, 2010 by   Filed under Webmaster

There are several reasons why you’d want to show author information blocks on your site. It could be either because you have multiple authors, or you allow for guest posts on your blog. One of the reasons why people would want to guest post is because they can gain some extra exposure.

A cool way of doing this is using the built-in author functions with some extra’s to add a “Guest post by” block to your template.  you can find an example here.



How I did this? Using Gravatars and the new author_meta functrions in WordPress of course!

WordPress has added template tags you can use to show author info and Gravatars, so it’s pretty easy. So you can just add the following code to your theme. I’ve annotated all lines, you should be able to copy paste and modify:

<?php
  // If it's not written by me (username admin), it's a guest post,
  // hence check for that:
  if (get_the_author_meta('user_login') != "admin") {
        // If it's a guest post, show the appropriate block
?>
    <div id="
      <?php the_author_meta('user_email'); ?>">
<?php
        // Make sure the image is right aligned
        function avatar_align($avatar) {
            return str_replace("class='","class='alignright ",$avatar);
        }
        add_filter('get_avatar','avatar_align',10,1);

        echo get_avatar( get_the_author_meta('ID'), '60' );
        // Show the author's information
?>
        <h3>Guest post by: <?php the_author_meta('display_name'); ?></h3>
        <p><?php the_author_meta('description'); ?></p>
    </div>
<?php
    }
?>

The last thing is that, in order for HTML to be allowed in user profiles,
you need to add the following line to your themes functions.php:
// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');

That’s it! You now have cool “Guest post by” blocks on your site!

Note:This tutorial is based on the popular StudioPress Themes and while most StudioPress/Revolution themes use the same division names in their code, not all do. Also, if you are using this for a non-StudioPress Theme (tsk, tsk) your division names will be different from the code used in this tutorial.

SOURCE:http://www.studiopress.com/wordpress-tips/how-to-add-author-information-blocks-to-your-site.htm
AUTHOR:Joost de Valk

Acronis True Image 2011 Specialoffer 468x60