Display image (if present) and/or name for the author of a post, or for all authors on the blog.
<?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”)
<?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:
- 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.
- 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
- 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
$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’.
- You can take advantage of the
$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.
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
- Download the file author-images.zip and unzip it into your /wp-content/plugins/ directory.
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 ?>
- Optional: Change configuration options in the file to your liking. In-code comments should help you there.
- Activate the plugin from your WordPress admin ‘Plugins’ page.
- Create the directory(s) that will contain author image(s) (by default this would be /wp-content/images/authors/)
- 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
- 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.)
- 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.
- 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
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
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(); ?>
- 27 Mar 2005 : v0.9 — Released to the public
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.