Categories
Package/plugin/module WordPress

Plugin: Author Image(s)

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/author-images
Name:
Author Image(s)
Author:
Scott Reilly
Version:
0.9
Last updated:
27 March 2005
Description:

Display image (if present) and/or name for the author of a post, or for all authors on the blog.

Notes:

Use <?php c2c_the_author_image(); ?> as a replacement for <?php the_author() ?> in index.php (and other post templates) to display an image for a post’s author (inside “the loop”)

Use <?php c2c_wp_list_authors_images(); ?> as a replacement for <?php wp_list_authors(); ?> in the sidebar section of your site to list all authors for the blog using an image and/or text.

PROCESS BY WHICH IMAGE IS LOCATED OR TEXT USED INSTEAD:

  1. If a post has an ‘author_image’ custom field defined, the plugin checks if the value is the valid name of an image in $image_dir. If not, it appends each of the defined $image_extensions, in turn, to custom field’s value, then checks if an image can be found.
  2. If no image has been found yet, it looks under $image_dir for a file with a name that is the author’s ID with a file extension matching one of the ones defined in $image_extensions

NOTES:
– There are three configuration settings coded into the file:
* $show_name_AND_image, which is defaulted to ‘true’. If set to ‘true’ then the author’s name will be displayed immediately following the image; if set to ‘false’, only the image (if found) will be displayed.
* $show_name_if_no_image, which is defaulted to ‘true’. If set to ‘true’ and an image can’t be found, the author’s name will displayed as text; if set to 0 and an image can’t be found, then no information regarding the author is displayed.
* $link_type, which is defaulted to ‘posts’ (other possible values are ‘site’ and ‘none) indicates what to link the author image/name to

c2c_the_author_image() is a drop-in replacement for WordPress’s the_author() , allowing the author for the post to have an image displayed in lieu of the name (if an image can be found). If $image_extensions is set to “”, then the function behaves just like the_author() (assuming $show_name_if_no_image is also set to 1)
– Images output by c2c_the_author_image() are defined with class="author_image" for stylesheet manipulation
– If $image_extensions is defined, but no image is found for the author, then nothing is displayed for that author.

c2c_wp_list_authors_images() is a drop-in replacement for WordPress’s wp_list_authors(), allowing all authors for a blog to be listed with an image (if present)
– Images output by c2c_wp_list_authors_images() are defined with class="list_author_image" for stylesheet manipulation

$image_extensions can be defined as a space separated list of image extensions. Files will be checked with the image
extensions in the order those extensions were provided; default is ‘png gif jpg’.

TIPS:
– You can take advantage of the $image_extension and/or $image_dir arguments to display different author icons under different contexts, i.e. if showing a post on a permalink page, choose to use a ‘png’ image, otherwise use ‘gif’; or locate your images in different directories ‘/wp-content/images/authors/small/’ and ‘/wp-content/images/authors/large/’ and decide on context where to get the image(s) from.

CONFIGURATION OPTIONS:
The following configuration options are defined in the file; feel free to change them:


$show_name_AND_image = true;  // Set this to 'true' to show author's name immeidately after author image; set to 'false' to only show the author image
$show_name_if_no_image = true;  // Set this to 'true' to show author name if no author image is found; set to 'false' to refrain from showing anything if no author image is found
$link_type = 'posts';    // can be 'posts', 'site', or 'none'
        //  'posts' links author image/name to a page of all of author's posts on this blog
        //  'site' links author image/name to the author's home site, if specified in author's profile
        //  'none' does not hyperlink the author's name

Installation:
  1. Download the file author-images.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( author-images.phps ) into a file called author-images.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: Change configuration options in the file to your liking. In-code comments should help you there.
  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
  4. Create the directory(s) that will contain author image(s) (by default this would be /wp-content/images/authors/)
  5. Put images into the specified image directory, using the author ID as the filename, with whatever extension you plan to support, i.e. 1.gif
  6. Modify your index.php and/or other template files to include calls to <?php c2c_the_author_images(); ?> and/or <?php c2c_wp_list_authors_images(); ?>. (Read the rest of these notes for more info.)
  7. Optional: add the custom field ‘author_image’ to posts to explicitly define an image for the author for just that post. Otherwise, the plugin will proceed to attempt to find the author image.
  8. Optional: add the class “author_image” to your CSS file to control the dispaly of image produced by c2c_the_author_image(), and/or add the class “list_author_image” to your CSS file to control the display of the images listed by c2c_wp_list_authors_images()
Functions:

function c2c_get_the_author_image ($idmode = '', $before = '', $after = '', $image_extensions = 'png gif jpg', $image_dir = '/wp-content/images/authors/')

  • $idmode : (optional) id mode indicating the manner in which the author’s name is presented; default is ”, which displays user’s nickname
  • $before : (optional) text or HTML to be displayed before the author image and/or name
  • $after : (optional) text or HTML to be displayed after the author image and/or name
  • $image_extensions : (optional) a space-separated list of image extensions to consider for use for the image(s) to be displayed, in the order they are to be considered; if defined as ” then no image is retrieved and the category name is displayed instead (a la the_category()); default is ‘png gif jpg’
  • $image_dir : (optional) the directory in which to look for the image(s); default is ‘/wp-content/images/authors/”

For use in templates:

function c2c_the_author_image( $idmode = '', $echo = true )

  • $idmode : optional; id mode indicating the manner in which the author’s name is presented; default is ”, which displays user’s nickname
  • $echo : (optional) indicates if the author image and/or name should be displayed on the page; default is ‘true’

function c2c_wp_list_authors_images( $args = '' )

  • $args : URL query string formatted arguments; valid option values are: optioncount, exclude_admin, show_fullname, hide_empty, feed, and feed_image
Tips & Examples:

In your index.php, instead of having this default WordPress call for the author’s name:
<?php the_author(); ?>

Use this instead:
<?php c2c_the_author_image(); ?>


In your sidebar.php, if you would like to list all of your authors, try this:
<?php c2c_wp_list_authors_images(); ?>

Release Log:
  • 27 Mar 2005 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
N/A

62 replies on “Plugin: Author Image(s)”

Hey man, i am currently building a site for me and my friends…. www.marathonation.com (i’m working on a custom design so please forgive the design!) What I am interested in is if you could point me in a direction of how i can use your plugin to insert a random author image instead of a static one… would this be a huge deal? I’m not looking for you to do it for me, i’m trying to learn some php… so if you could point me in a direction or any advice you could offer… that would be great…

my email is ahreno @ ahreno (dot) com

ahreno: I would probably suggest using my Random File plugin to do random images. In your images directory, create a subdirectory for each author (using their author ID as the subdirectory name). If you need help with it follow up on the page for Random File.

Z: I hadn’t thought of that; good idea. Currently the plugin isn’t geared to work in the comments section, but it could definitely be made to do so. I’ve added it to my to-do list.

Hey,

I’ve just installed your plug-in for the author images. I’m just wondering how/if I can get the author name to break and appear under the image, instead of being a long line of the image, directly followed by the author name.

I also noticed the tips or whatnot for inserting whatever you want before, or after that whole group of the image and name, but how do I put something in between? Like a !

And then I worry still that breaking the line there would just cause the name to ooze all the way to the left instead of center under the image.

Can this be remedied?

I have followed all the installation instructions. My index code is by
, but the site is not displaying anything after the word "by" (Title, time/date, by ... nothing). I tried deleting everything and starting over but no luck. I also tried playing around with spaces, etc. Any ideas what I am doing wrong?

Thanks!

Josh

If i want to have 2 types of pictures. 1 small that will appear in every post that a certain user writes and 2. a big picture that will be shown in the users profile page.

How can I make it work? How do I retreieve the right pictures?

like:
‘/wp-content/images/authors/small/’
‘/wp-content/images/authors/bigl/’

?

Hi! Love the plugin, but there’s a bit of functionality I’d rather have instead, and was wondering if you could help me out 🙂

I’d like to be able to select from a list of avatars that I either insert into a database or store in a directory on the server, much like Livejournal users are able to do, and have this avatar display on the post.

Example: unbeliever.net/testbed/

I manually hacked the main template to show this, but I can’t seem to figure out how to be able to select the image.

I’d be willing to donate a little if you’re willing to help 🙂

When you say it’s a “replacement” for , I hope you mean that you can use it as a replacement but it doesn’t make the_author go away. I just want the picture and will continue using the_author for other stuff. Wish me luck!

[…] As as special bonus! categories: tampa, SoF – the site, redesign, site info, contributors by Brett @ 1:05 am Tommy asked for this a while ago – but it’s amazing what a sore throat, some nap time, and someone else’s WordPress upgrade does for my productivity. Author images (brought to you by your friends at Coffee 2 Code) are now available. Now, you too can see just who comes up with this stuff on a daily basis. […]

hey great job on the plugin.

i’m making a author.php template page, like a profile page for each author on the blog, and i’m trying to display a user picture for each profile. this is exactly what i needed, but it can only be used inside of the template loop.

is there antway to make it display OUTSIDE the loop?

thanks for your time.
Ronny.

corey. did you follow the instructions in the read me regarding the naming of the photos and the directory to put them.

if you are intent and you follow the readme, you should be able to get it done in no time. 🙂

Wicked awesome plugin! Thanks so much. I also have a question/request.

All my images are in 1 directory, thumbs and regular pics. Do you know how to get the thumbs in a seperate directory (just by using the “Write” dialog)?

If not, is ther ea way to use only certain filenames? My thumbs are format filname.thumbnail.jpg

Can I tell it to look for only *.thumbnail.jpg ?

Thanks, and keep up the great work!

Hehe..yes i’ve got everything in the corect location.

Well now i’m getting this
Unknown column ‘user_nickname’ in ‘field list’
it appears to be looking for “admin” instead of the nickname for the admin.
how can i verify that it’s really using the nickname?

author-images.php, line 111 & line 144:

<i>$image_dir = '/wp-content/images/authors/'</i>

should be

<i>$image_dir = '/wp-content/images/authors'</i>

or it will request wp-content/images/authors//1.jpg. No problem with Firefox and IE, but doesn’t look so good.

I’m lovin’ the plugin! Great work.

One thing, when I try to add:

in sidebar.php, I get the following error:

WordPress database error: [Unknown column ‘user_nickname’ in ‘field list’] SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from wp_users WHERE user_nickname ‘admin’ ORDER BY user_nickname

any ideas?

Great plugin! Works very well.

I’m trying to use different images in different contexts as you mention in the readme. I’m using the following call within the loop but get nothing.

What am I doing wrong.

Thanks in advance – Michael

I got this error, could you help?

WordPress database error: [Unknown column ‘user_nickname’ in ‘field list’]
SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from wp_users WHERE user_nickname ‘admin’ ORDER BY user_nickname

Warning: Invalid argument supplied for foreach() in /home/ucenglis/public_html/wp-content/plugins/author-images.php on line 191

Great plug in. I got it to work but can’t get it to work with my theme. How would I work it into my CSS? I tired adding it but no luck.

I too got this error!!

WordPress database error: [Unknown column ‘user_nickname’ in ‘field list’]
SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from wp_users WHERE user_nickname ‘admin’ ORDER BY user_nickname

Somehow I could make the image show up, instead it shows the author’s name and other posts. I uploaded the image like it says in the installation description. But I won’t complain; this is great. You can check it out here: ProTibet.com
Thanks for the great plugin.

What I want to do on my blog, is every few hours take the oldest post and move it to the
front of the queue, all automatically. Anyone know if there is a plugin that can do this or
a simple way to set up another plugin to do this (use my own feed perhaps)?
Thanks.

Alright, I have tried getting it to work, but it isn’t. It is linking like it should, but it isn’t grabbing the pictures. I have put them under the /wp-content/Images/Authors folder.
I don’t know what I am missing. Are there any changes that need to be made other than what is on the installation section?

Figured out the problem. For those who are having problems, make sure that you don’t have any of your directories capitalized unless you have them capitalized in the php line that references the pictures. Also, make sure that you name the pictures as numbers, like instead of naming my picture aaron.jpg, it has to be 2.jpg .
Just trying to help out the community.

Could someone please instruct me exactly what to do to get this to work. So far I have done:
1. Downloaded the zip and unzipped it to /wp-content/plugins/
2. Did not change configuration options in the file author-images.php since it’s optional.
3. Activated the plugin.
4. Created folder /wp-content/images/authors/
5. Put my image named same as my id, 4.jpg
6. Pasted the follwing lines:

to index.php
7. Pasted the following line to sidebar.php:

Sidebar gone, template strange and the following message occurs:

Fatal error: Call to undefined function c2c_the_author_images() in /var/www/wp-content/themes/default/index.php on line 27

I am very stupid, please give me exact instruction so I can get this working. Thanks alot!

Hi.
I have managed to display author images next to their posts, but when I try to list out the authors I get a query error. “Unknown column nickname…”. I see that others strive with the same, but can’t find any solution. I have wp 2.x. I know the users first name and last name is somewhere in the database, but can’t figure out where. It is not in my wp_users.

could you please help me out here?

Comments are closed.