Hi,

I'm somewhat new to Drupal and so far it's been easy to customize and install modules.

I'm able to give a user the ability to choose a theme - however this only affects the way they see the site when logged in. What I'd like to do, is let the user choose a theme which would become the main theme for their profile page, regardless of who's looking at it (un-registered users, admin, etc.). So in turn, each user can change the appearance of their profile page to whatever theme they choose.

Is it possible to do with an existing module or setting?

Thanks in advance

Comments

MoonchildCH’s picture

I just solved this tonight! I created a little module that lets the user determine the theme in which their profile is viewed. It also sets the front page to default, and everything else to the user's theme. I tried working through the template.php, but I had to make a module to get the $custom_theme to work. I'm not sure it's exactly right, but I'm sure it works!

function lulu_theme_init() {
  global $custom_theme, $user, $theme_default;

  $theme_default = variable_get('theme_default', '');
  $user_theme = variable_get('user_theme',$user->theme);

//  This is the part that sets the theme for the front page.  Mine is the default.
  if (drupal_is_front_page()) {
      $custom_theme = $theme_default;
  }

//  This is the part that sets the theme for the profile to the user's account theme or default.
  elseif (arg(0) == 'user') {
    $result = db_query('SELECT u.theme FROM {users} u INNER JOIN {profile_values} pv on u.uid = pv.uid WHERE u.uid = %d', arg(1) );
    $account_theme = db_result($result);
    $custom_theme = !empty($account_theme) ? $account_theme : variable_get('theme_default', '');
  }

// This sets everything else to the user's theme.
  else  { 
    $custom_theme = $user_theme;
  }

}

I hope this helps you. I also added the following to mytheme_preprocess_user_picture in my template.php file (at the end of the first if-statement). It returns a theme-specific default picture.

global $theme;

  if ...

    else {
variable_set('user_picture_default', 'sites/all/themes/'.$theme.'/default_picture.png');
  $picture = variable_get('user_picture_default', '');
    }

...

Have fun!

mwork’s picture

Thanks for the work around - I'm really new to Drupal and not sure where I should paste this function (in which file and where). In addition to pasting this into the document, do I also have to call the function at some point?

MoonchildCH’s picture

The first part stands alone in a file called sites/all/modules/lulu_theme/lulu_theme.module (lulu is my base/default theme). In addition, it needs an info file in the same directory (e.g. lulu_theme.info) that looks like this:

; $Id$
name = Lulu theme
description = Specifies themes--default for front page, account theme for profile, user theme for other pages.
core = 6.x

Then you have to enable it in the Admin (site building/modules, I think). It doesn't add any menus for admin UI or anything. If you want to change the themes, you have to do it in the code. Clear the cache. Please let me know if/how it works for you.

As for the default picture, you can find the rest of that code here:
http://api.drupal.org/api/function/template_preprocess_user_picture/6

Drupal API is your friend!

MoonchildCH’s picture

The above code will set the admin theme to the user theme. To keep the admin theme, add this bit.

function lulu_theme_init() {
   ...
  $admin_theme = variable_get('admin_theme', '');
  ...
//  If you don't want the admin theme to show up as user theme, include this
  elseif (arg(0) == 'admin') {
    $custom_theme = $admin_theme;
}
  ...