Showing posts with label themes. Show all posts
Showing posts with label themes. Show all posts

Thursday, 9 December 2010

Changing page.tpl based on node type

Via here

If you use Drupal you may encounter the difficulty in setting up individual page.tpl.php for different node types. The is a simple solution to this problem but requires a few lines of code in your template.php file, found in your theme directory (/sites/all/themes/).

To begin:
Locate your template.php file in your theme directory.
At the bottom of your template.php file enter the following code:

function phptemplate_preprocess(&$vars, $hook) {
switch ($hook){
case 'page':
// Add a content-type page template in second to last.
if ('node' == arg(0)) {
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'page-' . $vars['node']->type;
$vars['template_files'][] = $node_template;
}
break;
}
return $vars;
}
The customizations can be seen in Devel along the lines of
page-node-1.tpl.php -> page-story.tpl.php -> page-node.tpl.php -> page.tpl.php.

If you have to use the forums feature of Drupal you may want to prevent a name clash by implementing:
$vars['template_files'][] = 'page-nodetype-' . $vars['node']->type;
instead of 
$vars['template_files'][] = 'page-' . $vars['node']->type;

Custom template for nodes of type "page"

A common query is :

if i want to override page.tpl for nodes of type "page" what is the name is the tpl file I should use - node-page.tpl.php or page-node.tpl.php?

Theme Developer module to the rescue (available here) : the answer is :

page-node.tpl.php

Friday, 3 December 2010

Gpanels and Adaptivetheme - creating a two column section for blocks

Video tutorial over here

Gpanels are easy to use PHP and HTML snippets for creating multi column layouts. The idea is you copy/paste them into page.tpl.php (where ever you want) and place blocks into the regions to create columns of blocks.

Gpanels come with both Adaptivetheme and the Genesis starter theme.

This video walks you through the process of adding a Gpanel, enabling the regions and CSS, and then placing the blocks in the newly available regions.


Gpanels & Adaptivetheme: Create a 2 column section for blocks from Adaptivethemes on Vimeo.