Displaying Author Pic and Bio in Your Wordpress Post the Non-Gravatar Way

Also see Enabling Author Pic and Bio for WordPress Single Posts for displaying an author bio box on a post by post basis.

A lot of sites/blogs out there have guest posts and/or multiple authors who contribute content on a regular basis. Now, there is nothing new with displaying the author name of a post, that snippet of code is just

<?php the_author(); ?>

and will simply display the authors name. We want to get a little more stylish and display a bio with an image, usually you can find a small bio of the article author before or after the post you are reading. 2 quick random examples can be seen below:

Steven Snell(Vandelay Design and DesignM.ag) is a contributer to the popular site PSDTuts, they do an author pic/bio before the article.

From Steven’s 20 Photoshop Painted Inspiration and Brush Resources

Author Bio - PSDTuts

Adelle Charles runs FuelYourCreativity.com in which she displays an author pic/bio after the article.

From Adelle’s Micromanaging a Creative

Author Bio - PSDTuts

Both of these examples display a little information about the author along with a link to the author’s site. Who doesn’t love some link love?!

Both are also are calling in the author’s Gravatar (Globally Recognized Avatar) that is linked to the author’s email*.

*For those who don’t know you can import an author’s image using the gravatar code:

<?php echo get_avatar( get_the_author_email(), '80' ); ?>

In which the author’s email will be checked with Gravatar, if the person has an account the image linked to their email will be displayed, exact same concept of pulling in avatars in the comments section of your favorite site.

But what happens if the author doesn’t have a Gravatar account?

Hmm…interesting.

Ok first thing first, make sure your author is listed as a “User” for your site. If they are not listed, create the account:

Go to your WordPress dashboard>>Users>>Authors>>Profile

Make sure the section for the Bio Info is filled out and while your at it make sure the First Name, Last Name and Nickname are filled out as well…they will come in handy later on.

Now open your Single Post php file, usually single.php. This page generates the layout of your article and is the file you need to edit in order to display some author info. For my example I added the author bio after the article, right before the share options and comments.

1
2
3
<div class="authbio">
<?php the_author_description(); ?>
</div>

Yikes, ugly but it works!

Let’s add some quick CSS to make it look somewhat respectable, you can always style away later!

1
2
3
4
5
6
7
8
9
10
.authbio{
color: #666;
font-weight: normal;
background: #fff;
border: 1px solid #ccc;
width: 420px;
height:60px;
padding: 8px;
margin-bottom:5px;
}

Okay, so now we are pulling in the author’s bio…what about the image?

Remember all the author fields you were suppose to fill out? First Name, Last Name, Nickname…if you didn’t do it, go do it now!

Let’s add these lines before your the_author_description in your single.php file.

1
<img src="<?php bloginfo('template_url'); ?>/images/<?php the_author_firstname(); ?>.jpg" alt="" class="alignleft"/>

Your author image and bio should now look like this:

1
2
3
4
<div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php the_author_firstname(); ?>.jpg" alt="" class="alignleft"/>
<?php the_author_description(); ?>
</div>

What the above means:

The above img src is looking for a file in your “Your Theme Stylesheet Directory/images” folder aka www.yoursite.com/wp-content/themes/ThemeName/images/.

php the_author_firstname is the first name used in the author fields under dashboard>>users>>profile

Please note that this is just returning what was entered into the First Name field and not the complete author name. Finally the extension “.jpg” is appended to the name.

Now you just need to upload a photo to your: www.yoursite.com/wp-content/themes/ThemeName/images/ and name the file exactly the same name you placed in the First Name Field in the author profile.

Throw in a little CSS to clear up the spacing

1
2
3
4
5
6
7
8
img.alignleft {
    float:left;
    background-color: #fff;
    border:1px solid #ccc;
    padding: 4px;
    margin: 0 7px 2px 0;
    display: inline;
}

And we are looking pretty much done!

Things to remember:

You can put links in your bio, no need to forget to link back to your site.

The above technique is looking for an image labeled the same as the “First Name” of the author. Also try the_author_lastname(); or the_author_nickname();

The technique above will provide a static solution for an author who does not have a Gravatar account. What is great about Gravatar is that the image will follow you wherever go as it’s linked to your email address. If you change your Gravatar image I believe it will be reflected everywhere you have left a comment, written a guest post etc. Using a Gravatar helps your personal branding to be consistent throughout the web.

Hope this is helpful, as I used it as a solution for an guest author who has an offline presence.

First Impressions: Google Voice Search

Google Voice Search for the iPhone is now available via the Google Mobile App. It works as stated, not only functional but fun as well.

Before using the Voice Search you will need to turn on the feature under “Settings” when you launch Google Mobile App. Don’t forget the instructions as “Voice Search only works in English, and works best for North American English accents.”

After you turn on the settings, just put the phone to your ear and the proximity sensor in your iPhone will start the process of recording your voice with a little beep. Speak regular into the phone and then just move the phone away from your ear.

Watch as Google does it’s magic.

And finally you are presented with your search results which are now optimized for your iPhone which are in the same fashion we are used to, just laid out more efficiently for your iPhone.

Of course Voice Search is cool in itself but when you launch the app, it will ask you if it can use your current location. By just saying “Movie Times” in the app I was able to pull up the times for the nearest theater.

Sure beats opening up an app, typing in the zip code of your location and then choosing the nearest theater! I also tested out some random searches which all returned what I was looking for. Overall, if you have an iPhone you probably already have the previous version of the Google Mobile App installed, just update and you’ll be all set. Else download the Google Mobile App from the iTunes Store and test away, you’ll be surprised how well it works and may definitely change the way you search on your iPhone.

Fixing Your Image Gallery for WordPress

Most new themes will include the proper image.php file for the WordPress 2.5+ gallery but if not here are a few quick snippets of code that may help.

When using the gallery features with WordPress 2.5+ you are able to upload many photos to a post/page and then insert the entire gallery using the shortcode:

1
[gallery]

When viewing individual images WordPress will automatically look for a image.php, then an attachment.php following the WordPress Template Heiarchy. If your theme doesn’t have either just copy your single.php or index.php and rename it to image.php or attachment.php

Don’t forget to start of your new page with the proper label:

1
2
3
4
5
<?php
/*
Template Name: attachment
*/
?>

In the content area of you page, IE post, content, post entry…you can use the following to call in the image:

1
2
<p class="<?php echo $classname; ?>"><?php echo $attachment_link; ?>
<br /><?php echo basename($post->guid); ?></p>

For a snazzy before and after image preview under your image you can use:

1
2
3
4
5
<div class="imgnav">
<div class="imgleft">previous image<br /><?php previous_image_link() ?></div>
<div class="imgright">next image<br /><?php next_image_link() ?></div>
</div>
<br clear="all" />

Style it with some CSS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/****************Image Gallery *********************/
.gallery {text-align:center;}
.gallery img {padding:2px; height:100px; width:100px;}
.gallery a:hover {background-color:#ffffff;}
.attachment {text-align:center;}
.attachment img { padding:2px; border:1px solid #999999;}
.attachment a:hover {background-color:#FFFFFF;}
.imgnav {text-align:center;}
.imgleft {float:left;}
.imgleft a:hover {background-color:#FFFFFF;}
.imgleft img{ padding:2px; border:1px solid #999999; height:100px; width:100px;}
.imgright {float:right;}
.imgright a:hover {background-color:#FFFFFF;}
.imgright img{ padding:2px; border:1px solid #999999; height:100px; width:100px;}

I know I took the above CSS from somewhere so please let me know if it’s yours to provide credit. What the above will do is fix the spacing issue between the default WordPress image gallery along with add some style and function to your single image page.

This code has help me before and now I just about copy and paste it through any WordPress install I have running, so hopefully it will help some of you as well!

Easy Featured Post for WordPress

Creating a featured post section for your most recent post has quickly become one of the most widely used features for many templates.

The ScatterBrain WordPress Theme uses a featured post section in which the latest post is displayed with a large image which is attached to the post using the “Custom Fields” found when publishing a post. So let’s do a quick run through of the code so we can all understand the process.

Here is the full code for reference that is used in the ScatterBrain WordPress Theme which we will be dissecting:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<div id="latest_post">   
<?php $the_query = new WP_Query('showposts=1');
while ($the_query->have_posts()) : $the_query->the_post();?>
<h3 class="sections">Latest Story</h3>
<div class="postMeta"><span class="date"><?php the_time('m.d.y') ?></span></div>
<?php if ( get_post_meta($post->ID, 'home_image', true) ) { ?>
<div id="latest_post_image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/latest/<?php echo get_post_meta($post->ID, "home_image", $single = true); ?>" alt="<?php bloginfo('name'); ?>: Latest post" width="470" /></a>
</div>
<?php } ?>
<h3 class="latest_post_title" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h3>
<p><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?></p>
<div class="latest_post_meta">
<span class="latest_read_on">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/read.gif">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Continue Reading</a></span>
<span class="latest_comments">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/comment.gif">
<?php comments_popup_link('Post a comment', 'One comment', '% comments', '', 'Comments off');?></span>
<?php $cat = get_the_category(); $cat = $cat[0]; ?>
<span class="latest_category">Category: <a href="<?php echo get_category_link($cat->cat_ID);?>"><?php echo $cat->cat_name; ?></a></span>
</div>
</div>   
<?php endwhile; ?>

Query Your WordPress Posts:

2
3
<?php $the_query = new WP_Query('showposts=1');
while ($the_query->have_posts()) : $the_query->the_post();?>

What the above means:
Hey WordPress, for this section I want to call upon and use 1 post. Luckily for use the “1 post” will always be the latest post across all categories. If you want to show 1 post from a specific category, use (’showposts=1&cat=11′) where cat= is the category ID of the category you wish to pull from. You can also use category_name= to name a specific category or exclude categories from this query. See the Query Posts Templates Tag WordPress Codex for a full rundown of parameters.

Section Label and Date:

4
5
<h3 class="sections">Latest Story</h3>
<div class="postMeta"><span class="date"><?php the_time('m.d.y') ?></span></div>

What the above means:
Line 4 is labeling the section. Line 5 is pulling the date of the post entry. There are several options for the format of the date and time, review the Formatting Date and Time WordPress Codex for more info.

Looking for the Image:

6
<?php if ( get_post_meta($post->ID, 'home_image', true) ) { ?>

What the above means:
Here we start our “If” statement to look for a custom field named ‘home_image’ which you set when you are writing your post. Custom fields consist of a Key and a Value, in this case our Key is ‘home_image’ and our value is our image name. For every post that is to appear in the featured area you would add a value or image name to the Key of ‘home_image’.

Setting the Image:

7
8
9
10
<div id="latest_post_image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/latest/<?php echo get_post_meta($post->ID, "home_image", $single = true); ?>" alt="<?php bloginfo('name'); ?>: Latest post" width="470" /></a>
</div>

What the above means:
First we need to make sure to link the image to it’s post, line 8 starts the link wrap for the image as the href= will be linking to the post permalink.

Line 9 may be long but all we are doing is pulling in an image.

The first part of our image source aka img src= is pointing to a directory located within the theme called images/latest. I use this so I can just dump images to the folder via ftp but you can change this to point to your uploads folder and add images via the WordPress built in media gallery.

The second part of the img src= is naming the file in the images/latest folder. So get_post_meta($post->ID, “home_image”, $single = true); is pulling in the value you set in your Custom Field for the key of “home_image”. If your image was called home.jpg the img src from above would essentially be “Your Theme Stylesheet Directory/images/latest/’home_image’” or “Your Theme Stylesheet Directory/images/latest/home.jpg”

Post Title:

12
13
14
<h3 class="latest_post_title" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h3>

What the above means:
Again we use the_permalink() to link the title to it’s permalink while the_title() pulls in the title.

Post Title:

15
<p><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?></p>

What the above means:
Pull in the excerpt!

Post Title:

16
17
18
19
20
21
22
23
24
25
<div class="latest_post_meta">
<span class="latest_read_on">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/read.gif">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Continue Reading</a></span>
<span class="latest_comments">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/comment.gif">
<?php comments_popup_link('Post a comment', 'One comment', '% comments', '', 'Comments off');?></span>
<?php $cat = get_the_category(); $cat = $cat[0]; ?>
<span class="latest_category">Category: <a href="<?php echo get_category_link($cat->cat_ID);?>"><?php echo $cat->cat_name; ?></a></span>
</div>

What the above means:
This is the code for the bottom area which contains the Continue Reading Link, Number of Comments and displays what Category the post came from. The first two sections have an image followed by a text link. Each section is wrapped with a span class such as latest_read_on, latest_comments and latest_category.

If all goes well, and with some CSS you will end up with an image, title, excerpt and read more, comment and category:

I tried to keep it short on the areas which were a little more self explanatory but if there’s any questions feel free to ask. Overall line 2 is where the magic happens in which you’re telling WordPress where to look at how many posts to pull for your section. Line 6 is where you tell WordPress to look for your custom Key while line 9 is where you swap your Key for a Value.

Page 3 of 5« First...2345

Contact

Questions, inquiries or just feel like getting in touch, feel free to do so: