Changing the background image of a Drupal page based on user choice ...?

I am trying to give my users functionality to change what the background image on the page is using.

The list of background images will be a small number that will not change.

I thought I could add a few taxonomy terms ... one for each background type ... then apply the class to the body tag when viewing the page.

Does this sound like that, and if so, how do I do it?

thank

Sam

+5
source share
1 answer

EDIT: revised answer after clarifying my misunderstanding of the question

(node), . CSS, / node.tpl.php, $node. , .

$body_classes page.tpl.php, zen_preprocess_page(), , ( ) / preprocess_page(), zen :

function yourModuleOrTheme_preprocess_page(&$vars) {
  // Add classes for body element based on node taxonomy
  // Is this a node page?
  if ('node' == arg(0) && is_numeric(arg(1))) {
    // Yes, extract wanted taxonomy term(s) and add as additional class(es)
    $node = node_load(arg(1));
    $background_vid = yourFuntionToGetTheBackgroundVocabularyId(); // Could be hardcoded, but better to define as variable
    $terms = $node['taxonomy'][$background_vid];
    foreach ($terms as $tid => $term) {
      // NOTE: The following assumes that the term names can be used directly as classes.
      // You might want to safeguard this against e.g. spaces or other invalid characters first.
      // Check the zen_id_safe() function for an example (or just use that, if zen is always available)
      $vars['body_classes'] .= ' ' . $term;
    }
  }
}

. .


( ), OPs, , :)
, :

, , , "" . , (, ) "background" ( " " ). ( , ), , . :

global $user;
// NOTE: The following call would be the explicit way,
// but usually the profile fields get added to the $user object
// automatically on user_load(), so you might not need to call it at all,
// extracting the values directly from the $user object instead
$profile = profile_load_profile($user);
$background = $user->profile_background
+1

All Articles