Community Documentation

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

Last updated January 24, 2008. Created by beekerstudios on January 24, 2008.
Log in to edit this page.

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>';
}
?>

Comments

Using an imagecache preset

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?

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

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

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?

will this work with D6?

thanks

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
"I would love to change the world,
but they won't give me the source code"
-JG

Kinda works in D6, only

Kinda works in D6, only problem is that it also displays the info on all the other pages so not only the blog.

Just an FYI

Since it's a block, you need to only allow it to be shown in the indicated URL's.

Since I use pathauto to rename all my user blog posts, to their username and a prescribed path for their entries, it works.

If you leave them all as node/# than yah this doesnt work.

You'd have to put in another if statement to check if it's a $node->type == "blog" (probably not 100% correct, but you get the idea) Mine is a little sloppier, but it also covers the base for the landing page for the main blog roll of each user.

Glad people are getting some use out of this.

I have got a Blog Author

I have got a Blog Author Block to work on

blog/username
blog/username/articletitle

I use pathauto to generate the links to userblogs.

For anyone has been finding this process hard or documentation lacking.

This is the code for my block. It uses the profile image as the blog picture and the fields About, Location and Currently playing from the Author's profile.


$view = new view;
$view->name = 'blogauthorimage';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'BlogAuthorImage';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Blog ';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '1';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: User: Picture */
$handler->display->display_options['fields']['picture']['id'] = 'picture';
$handler->display->display_options['fields']['picture']['table'] = 'users';
$handler->display->display_options['fields']['picture']['field'] = 'picture';
$handler->display->display_options['fields']['picture']['label'] = '';
$handler->display->display_options['fields']['picture']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['picture']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['picture']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['picture']['alter']['external'] = 0;
$handler->display->display_options['fields']['picture']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['picture']['alter']['trim'] = 0;
$handler->display->display_options['fields']['picture']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['picture']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['picture']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['picture']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['picture']['alter']['html'] = 0;
$handler->display->display_options['fields']['picture']['element_label_colon'] = 0;
$handler->display->display_options['fields']['picture']['element_default_classes'] = 1;
$handler->display->display_options['fields']['picture']['hide_empty'] = 1;
$handler->display->display_options['fields']['picture']['empty_zero'] = 0;
/* Field: User: About */
$handler->display->display_options['fields']['field_about']['id'] = 'field_about';
$handler->display->display_options['fields']['field_about']['table'] = 'field_data_field_about';
$handler->display->display_options['fields']['field_about']['field'] = 'field_about';
$handler->display->display_options['fields']['field_about']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_about']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_about']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_about']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_about']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_about']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_about']['hide_empty'] = 1;
$handler->display->display_options['fields']['field_about']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_about']['field_api_classes'] = 0;
/* Field: User: Location */
$handler->display->display_options['fields']['field_userlocation']['id'] = 'field_userlocation';
$handler->display->display_options['fields']['field_userlocation']['table'] = 'field_data_field_userlocation';
$handler->display->display_options['fields']['field_userlocation']['field'] = 'field_userlocation';
$handler->display->display_options['fields']['field_userlocation']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_userlocation']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_userlocation']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_userlocation']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_userlocation']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_userlocation']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_userlocation']['hide_empty'] = 1;
$handler->display->display_options['fields']['field_userlocation']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_userlocation']['field_api_classes'] = 0;
/* Field: User: Currently Playing */
$handler->display->display_options['fields']['field_usercurrentlyplaying']['id'] = 'field_usercurrentlyplaying';
$handler->display->display_options['fields']['field_usercurrentlyplaying']['table'] = 'field_data_field_usercurrentlyplaying';
$handler->display->display_options['fields']['field_usercurrentlyplaying']['field'] = 'field_usercurrentlyplaying';
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['hide_empty'] = 1;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_usercurrentlyplaying']['type'] = 'list_key';
$handler->display->display_options['fields']['field_usercurrentlyplaying']['field_api_classes'] = 0;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'user';
$handler->display->display_options['arguments']['uid']['default_argument_options']['user'] = TRUE;
$handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['uid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['uid']['validate']['type'] = 'user';
$handler->display->display_options['arguments']['uid']['validate_options']['type'] = 'either';
$handler->display->display_options['arguments']['uid']['validate_options']['restrict_roles'] = 0;
$handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['uid']['not'] = 0;
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$translatables['blogauthorimage'] = array(
  t('Master'),
  t('Blog '),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('About'),
  t('Location'),
  t('Currently Playing'),
  t('All'),
  t('Block'),
);

And here is step by step of those settings for those of us who do not understand the export code.

Create a new block
Format = Unformated List
Show = Fields

Fields
User Picture
User About <<- Pick whichever fields you want to display if you want more information

Filter Criteria
User Active Yes

Sort Criteria
User Created Date (desc)

Pager
Use pager: Display a specified number of items | 1 item
More link: No

Contextual filters
User :UID - settings as follows - Select "Provide Default Value" Type: USER ID FROM URL
Tick - Also look for a node and use the node author

Specify Validation
Validator User
Allow both numeric UIDs and string usernames

This works on my site: http://senilityguild.com/blog/kiwipearls

About this page

Drupal version
Drupal 5.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.