Showing posts with label Drupal Themes making. Show all posts
Showing posts with label Drupal Themes making. Show all posts

Saturday, January 30, 2010

Code for tab in drupal.

This conditional statement controls the tabs.
if ($tabs = theme('menu_local_tasks')) {
$output .= $tabs;
}

Tuesday, January 12, 2010

Code for active primary link in drupal.

In the page template.php in sites/all/themes/yourthemes paste the following codes:

function new_primary_links($start_level = 1, $pid = 0) {
if (!module_exists('menu')) {
return NULL;
}
if (!$pid) {
$pid = variable_get('menu_primary_menu', 0);
}
if (!$pid) {
return NULL;
}
if ($start_level < 1) {
$start_level = 1;
}
if ($start_level > 1) {
$trail = _menu_get_active_trail_in_submenu($pid);
if (!$trail) {
return NULL;
}
else {
$pid = $trail[$start_level - 1];
}
}
$menu = menu_get_menu();
$links = array();
if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
$count = 1;
foreach ($menu['visible'][$pid]['children'] as $cid) {
$index = "menu-$start_level-$count-$pid";
if (menu_in_active_trail_in_submenu($cid, $pid)) {
$index .= "-active active"; // **** HERE'S THE CHANGE
}
$links[$index] = menu_item_link($cid, FALSE);
$count++;
}
}
return $links;
}


After that,in page.tpl.php paste the following codes:

<?php
print theme('links', $primary_links);
?>


For more help: http://drupal.org/

Monday, January 11, 2010

Code for Building a .info File in drupal

As of Drupal 6, a .info file is required as part of a valid theme distribution. The
.info file contains a number of pieces of information intended to inform the system about the theme and to set configuration options. The syntax throughout this file is consistent, use key = value. Semicolons can be used to add comments or commentout options. In the event that optional values are not stated, the system will assume default values.
To get started, open up the .info file you created a short while ago and add
the following:First, a name key is required by the system. Note this is a human-readable value. Forour theme, this entry will appear as follows:
name = kajal
Next, let's add a description. This data will appear in Drupal's theme manager
alongside the theme name and screenshot. This key is optional but as it is very helpful, we're going to include some information here:
description = A simple theme for Drupal.
The core key is required to keep the system from disabling our theme due to
incompatibility.
core = 6.x
Add the engine key as follows (in the absence of this key, the system will assume this is a pure PHP theme):
engine = phptemplate
The regions key sets the regions available for block assignment. Note that this key is not necessary unless you wish to vary from the default set of regions. We've included the regions keys information in this example simply to show the variation in syntax that is required by this key. To set regions, use the following notation:
region[machine_readable_name] = human readable name, for example:
region[head] = Head
region[left] = Left Sidebar
region[right] = Right Sidebar
region[content] = Content
region[footer] = Footer

The .info file can be also used to enable the various theme configuration features, like the site mission, site name, logo, etc. To specify features use the syntax features[] = name of feature. In the absence of a contrary definition, the system will assume the presence of all the following:
features[] = logo
features[] = name
features[] = slogan
features[] = mission
features[] = node_user_picture
features[] = comment_user_picture
features[] = search
features[] = favicon
features[] = primary_links
features[] = secondary_links

Should you not want any of these features, simply delineate the ones you wish to see in the .info file and omit the ones you do not wish to see. As we want to enable all the default features, we need to add nothing to our .info file. In this fashion, the system will enable all the default features, above, giving our site administrator the widest number of configurations for Kajal.

With all the options above (and more), .info files can be quite lengthy. The
garland.info file (themes/garland/garland.info) for example, shows a relatively complex .info file. However, given our new theme's heavy reliance on default values, our .info file will be short and sweet:
name = Kajal
description = A simpletheme for Drupal.
core = 6.x
engine = phptemplate

Code for footer in Drupal.

Though the author only declared two regions, left and right, he includes the
footer region in the code. This provides us with a good example of the function chameleon_regions() in action. The function defines which regions will be available for the administrator to use for the assignment of blocks. In this case, only left and right are options for the administrator, despite the presence of the footer region in the code. Had the function chameleon_regions() been written so as to include 'footer' => t('footer'), then the region would be accessible to the administrator for block assignment. As it stands, however, the only output of the code below is the footer message, wrapped with a div.
if ($footer = variable_get('site_footer', '')) {
$output .= " <div id=\"footer\">$footer</div>\n";
}

Code for Title and Breadcrumb Trail in Drupal

The author places the title and breadcrumb together on the page and makes both subject to the appearance of the title; the title is also wrapped with the<h2> tag.
if ($title) {
$output .= theme("breadcrumb", drupal_get_breadcrumb());
$output .= "<h2>$title</h2>";
}

Code for side bar right in Drupal.

This snippet places the blocks designated for the right region into a table cell. Note the conditional statement; this allows the output to be hidden in the event that no blocks are assigned to the region. For styling, the table cell (td) is given an id name to reflect the placement (sidebar-right).

if ($show_blocks && !empty($blocks_right)) {
$output .= " <td id=\"sidebar-right\">$blocks_right</td>\n";
}

Code for side bar left in drupal

The following places the blocks designated for the left region into a table cell. Note the conditional statement; this allows the output to be hidden in the event that no blocks are assigned to the region. For styling, the table cell (td) is given an id name to reflect the placement (sidebar-left).

if ($show_blocks && !empty($blocks_left)) {
$output .= " <td id=\"sidebar-left\">$blocks_left</td>\n";
}

Code for primary and secondery links in Drupal

Chameleon combines the placement of the primary and secondary links, basically locking the secondary links into a subnavigation role. You don't have to group these two items together in this fashion, but it is one logical option. Note the snippet below. In both cases, the display of the links is conditional (depending on what is enabled by the administrator). If either one is enabled, then it will appear inside a div with the class navlinks. Additionally, to be able to style each set of links individually, both $primary_links and $secondary_links are provided with a unique class and id.


$primary_links = theme('links', menu_primary_links(), array('class' =>
'links', 'id' => 'navlist'));
$secondary_links = theme('links', menu_secondary_links(),
array('class' => 'links', 'id' => 'subnavlist'));
if (isset($primary_links) || isset($secondary_links)) {
$output .= ' <div>';
if (isset($primary_links)) {
$output .= $primary_links; }
if (isset($secondary_links)) {
$output .= $secondary_links; }
$output .= " </div>\n";
}

Code for siteslogan in Drupal

The following statement enables the site slogan to be toggled on or off, and wraps it with a div and a class for styling.

if (theme_get_setting('toggle_slogan')) {
$output .= " <div class=\"site-slogan\">". variable_get(
'site_slogan', '') ."</div>";
}

Code for sitename in Drupal

This snippet enables the site name to be toggled on or off, and wraps it with an H1 tag and a class.

if (theme_get_setting('toggle_name')) {
$output .= " <h1 class=\"site-name title\">". l(variable_
get('site_name', 'drupal'), ""). "</h1>";
}

Code for logo in Drupal

The following conditional statement enables the logo to be toggled on or off, wraps the image in an <a> tag and also sets the title and alt attributes.
if ($logo = theme_get_setting('logo')) {
$output .= " <a href=\"". url() ."\" title=\"". t('Home')
."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>";
}

Fav icon code in Drupal

The author deals with the setting of the favicon early in the document, prior to the output of the head of the document, and thereby makes the
tag available to the document head when it is output. All the other features, below, are placed in the body of the page where they will appear in the layout.


if (theme_get_setting('toggle_favicon')) { drupal_set_html_
head('<link rel="shortcut icon" href="'. check_url(theme_get_
setting('favicon')) .'" type="image/x-icon" />');}

Dynamically Styling Nodes

PHPTemplate provides a specific template for nodes—node.tpl.php. Using the
same principles of precedence we've seen throughout, you can provide alternative node templates to suit your needs. To provide a template for the blog node, for example, create node-blog.tpl.php; for the story node, node-story.tpl.php. In the absence of a more specific template, the system will apply the default node.tpl.php file. The table below shows the suggestions for the default system:

























Suggestion Affected node
node-blog.tpl.php blog entries
node-story.tpl.php story entries
node-page.tpl.php page entries
node-forum.tpl.php forum entries
node-book.tpl.php book entries

Dynamically Styling the Polls Module

The Polls module is the subject of a number of default templates. There are default suggestions available for all the key templates:



















Default templateSuggestion syntax
poll-results.tpl.phppoll-results-[block].tpl.php
poll-vote.tpl.phppoll-vote-[block].tpl.php
poll-bar.tpl.phppoll-bar-[block].tpl.php

Dynamically Styling the Forum Module

The base templates of the forum module is forums.tpl.php. There are several
options open for suggestions for both forum containers and topics:



























SuggestionWill apply to...
forums-topics.tpl.phpForum topics
forums-topics-[forumID].tpl.phpForum topics belonging to a forum of

a specific ID
forums-containers.tpl.phpForum containers
forums-[forumID].tpl.phpForum of a specific ID.
forums-containers-[forumID].tpl.phpForum containers belonging to a

forum of a specific ID

The Importance of Themes in Drupal

The theme of your Drupal site is responsible for the visitor's first impression of the
site. Given the key role in shaping the presentation, a theme is arguably the most
influential piece of your Drupal installation.
While the default Drupal distribution includes a set of themes that will prove
sufficient for many users, I assume you are reading this book out of a desire to do
more— whether it be only to install additional themes and then modify them to suit
your needs, or whether you plan to build your own themes from scratch.
ThisIn order to grasp better some of the challenges (and opportunities) associated with
Drupal themes, it is useful to look at three concepts that impact the way you use the
system and the way in which you must plan your theme deployment.