You’ve got a multiuser blog and want mugshots of the different proud authors next to their posts - this is how…
The key is to use the template tag the_author_ID()
This returns the numeric value of the user ID for the current post - unlike the category or categories of a post, it’s unique - so the programming becomes relatively simple. See wp-admin/users.php for the values on your blog
In strict programming terms, this is a bit of bodge - or you could say it takes advantages of the unique flexibility of PHP to dip in and out of HTML code. The following block of code needs to go within the Loop of posts on index.php. We are going to switch the value of $image_path according to the value of the function the_author_ID()
<?php
switch (the_author_ID())
{
case 1:
$image_path = ‘http://www.mysite.com/uploads/john.jpg’;
break;
case 2:
$image_path = ‘http://www.mysite.com/uploads/mary.jpg’;
break;
default :
$image_path = ‘http://www.mysite.com/uploads/default.jpg’;
}
?>
Don’t forget the break;
Probably best to use absolute urls in this case, especially if you’re using mod_rewrite seo-friendly urls. And the form of the post will be something like this
<div class=”post”>
<div style=”float:right;”><img src=”<?php echo $image_path; ?>” height=”140″ width=”100″ /></div>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
Further work
For perfection, you might want to use relative locations in the filesystem and check that the photo exists before outputting a broken path, using file_exists()
and, if not, supplying a default that you know does exist.
Also life is going to be easiest if all your photos are the same size - if you don’t want to make your life easy, something like this is the way to go:-
case (2):
$image_path = ‘http://www.mysite.com/uploads/mary.jpg’;
list($width, $height, $type, $attr) = getimagesize($image_path);
…
break;
But see getimagesize for details
There’s lots more to do with individual authors and their posts…
(These discussions assume some working knowledge of php and how to put it together - the code is given as suggestions, so you’ll need to do a bit more than just a cut ‘n paste to get results for your blog…)