inspired template

<?php
/**
* Implements theme_preprocess_page().
*/
function inspired_preprocess_page(&$vars) {
 
$vars['theme_path'] = drupal_get_path('theme', 'inspired');

 
// Ensure that we are editing with the admin theme
 
$arg0 = arg(0);
 
$arg1 = arg(1);
 
$arg2 = arg(2);
  if (
$arg0 == 'node' && is_numeric($arg1) && $arg2 != 'edit') {
   
$vars['template_files'][] = 'page-custom';
  }

 
// Render main menu
  //$vars['v']['main_menu'] = generate_main_menu();
}

/**
* Implements theme_preprocess_node().
*/
function inspired_preprocess_node(&$vars) {

 
$vars['theme_path'] = drupal_get_path('theme', 'inspired');

 
// Attach node data to article groups from articles
 
if ($vars['type'] == 'article_group') {
   
// Primary article
   
$primary = node_load($vars['field_agroup_particle'][0]['nid']);
   
$vars['v']['primary'] = $primary->v;

   
// Featured  and More articles
   
$vars['v']['featured'] = load_related_articles($vars['field_agroup_farticles']);
   
$vars['v']['more'] = load_related_articles($vars['field_agroup_marticles']);
  }

 
// See if any templates are bound to this content type
 
if ($vars['type'] != 'template') {
   
$result = db_query(
     
"SELECT n.nid
       FROM {node} n
       INNER JOIN {content_type_template} c
       ON c.vid = n.vid
       WHERE n.type = 'template'
       AND c.field_content_type_value = '%s'"
,
      
$vars['type']
    );

   
// Load the template data from its node
   
$nid = db_result($result);
    if (
is_numeric($nid)) {
     
$template = node_load($nid);
      if (
is_object($template)) {
       
$file = $template->field_template_file_name[0]['value'];
       
attach_template($vars, $file);
      }

     
// Merge the $v arrays
     
if (is_array($template->v)) {
       
$vars['v'] = is_array($vars['v']) ? array_merge($vars['v'], $template->v) : $template->v;
      }
    }
kpr($vars);
  }

 
// Check if the node has specified a template file
 
if (isset($vars['field_template_file_name'][0]['value'])) {
   
attach_template($vars, $vars['field_template_file_name'][0]['value']);
  }
}

/**
* Helper function to attach a specified template to a node
* @param array $vars
*  The variables preprocessed for a node template
* @param str $file
*  The file name of the template without a .tpl.php extension
*/
function attach_template(&$vars, $file) {
 
$vars['template_files'][] = $file;
}

function
load_related_articles($articles) {
 
$v = array();

  if (!empty(
$articles)) {
    foreach (
$articles as $article) {
     
$node = node_load($article['nid']);
     
$v[] = $node->v;
    }
  }

  return
$v;
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <a>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
My name is Kevin. I am a software engineer and bike geek living in Salem, Mass. I use Vim even when I don't need to. When I'm not on the computer, I'm usually hanging with my wife, Melissa and baby Benjamin or working on my pet project BIKENE.WS.