Blog Author Image, Name, and Signature (one php snippet to brand all blogs)

Last modified: January 24, 2008 - 20:28

This snippet, grabs a user's uploaded Profile Image, their account name, and their signature, and places it in a prescribed block (you decide where (i.e. left, right, menu, footer, header, etc.)). The idea here is you brand all blogs made by any user, with the authors info. This snippet intelligently figures out who the author of the blog is, and displays their respective info. You will need to place this in a block and only "show" the block for */blog and */blog/*. (I use pathauto to create /user/username/blog and /user/username/blog/blog-entry rewritten URI's). If anybody has any better methods by all means suggest away, I personally needed this to work, and this was simple enough to write.

Caveat: if you want more than 256 chars in the signature area, you will need to change the signature field type to something else (like mediumtext) in mysql in the users table. I only wanted mine a couple of chars longer than the allowed for varchar, and it kept chopping it, and I thought it was drupal, but it was just mysql.

So here goes:

<?php
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$args[0] = arg(1);
$node_id = $args[0];
$node = node_load($node_id);
$user_id = $node->uid;
} else if ((
arg(0) == 'blog') && is_numeric(arg(1))) {
$args[0] = arg(1);
$user_id = $args[0];
}

$user_load = user_load($array = array('uid' => $user_id));
echo
'<img src="/'.$user_load->picture.'" title="'.$user_load->name.'" /> <h3>'.$user_load->name;
echo
"'s Blog</h3>";
if(
$user_load->signature) {
echo
'<div id="user_sig">'.$user_load->signature.'</div>';
}
?>

Using an imagecache preset

messenger - June 12, 2008 - 02:15

I am using imagecache to resize my user's pictures.
I've only made a change to the img src path, it is now the path to the resized imagecache pictures.

echo '<img src="/files/imagecache/userpicture_profile_block/'.$user_load->picture.'" title="'.$user_load->name.'" /> <h3>'.$user_load->name;

many thanks for posting this, i was just about to delve into it and came across this.

Does this work for initial page listing the user's blogs?

topwaya - September 29, 2008 - 04:12

This is a really great snippet.
It works on each individual blog content page, but on the www.site.com/blog/username page, where it lists all the user's blogs, it doesn't work for me from the page's list link. It works when the link displays the actual number instead of the username.

When the link to the page is www.site.com/blog/username
it shows an empty picture placeholder and: 'S Blog.

When the link to the page is www.site.com/blog/123
It displays properly.

Any tricks to get it to work with the username version of the link?
Also, how would I do an if statement, in case the user doesn't have a picture?

Thanks for any help - this will be great!

node load and user load

hansrossel - October 14, 2008 - 04:17

If you don't need the signature it's not necessary to do also a user_load, author picture and name are available in the node_load:

<?php

print '<img src="/'.$node->picture.'" title="'.$node->name.'" /> <h3>'.$node->name;
print
"'s Blog</h3>";
?>

If you want the authors name to be linked to his account page use:

<?php

print '<img src="/'.$node->picture.'" title="'.$node->name.'" /> <h3>'.theme('username', $node);
print
"'s Blog</h3>";
?>

KOBA - Drupal Webdevelopment

what about cck image fields

emersonlenon - April 2, 2009 - 14:57

I don't use the built in user picture, instead I have a cck field.
I can't get this to work for me.
I have postings that follow the pathauto rule:
"mydomain.com/content/username/whatever..."
On each posting I want a block that displays the users cck profile image as a link to their profile.
Any advice on how to do this?
Thanks

D6?

jwells - June 22, 2009 - 10:34

will this work with D6?

thanks

 
 

Drupal is a registered trademark of Dries Buytaert.