Wednesday, November 23, 2011

Creating and Displaying Primary and Secondary Links

Creating and Displaying Primary and Secondary Links:
Create the Primary and Secondary links from the drupal admin end by,
Administer->Site Building->Menus->Primary Links or Secondary Links->Add item
There give the path that your primary that redirects to,next give title in the second field then give weight if u need.Then save it.Create more like this and print this in page.tpl.php or in your Header.php block using this code,

For Primary Links
<?php
 if (isset($primary_links)) {
 print theme('links', $primary_links, array('class' => 'links', 'id' => 'navlist'))
 } 
?> 
For Secondary Links
<?php
if (isset($secondary_links)) { 
print theme('links', $secondary_links, array('class' => 'links', 'id' => 'subnavlist'))
}
?>
 

To Create Header Block for a Site

To Create Header Block for a Site:

If you are creating a site with the header that will come all the pages.Then we can use this method for that thing,create a block as Header then define it in page.tpl.php

Create a block in the name of Header and use this code to print the header in your top of the page.tpl file.Then only you will get that header in all those pages,

               <?php
                    $block = module_invoke('block', 'block', 'view', 1(block id));
                    print $block['content'];
                ?>

How to open the Primary Liks or Secondary Links in New Tab

How to open the Primary Liks or Secondary Links in New Tab:

Give this code inside your template.php file,
For Example,your primary menu item class is menu-1 and its locate inside a <li class="menu1"><a href="<?php $base_path();?>contact_us"></a></li> tag then,
you should do like this,

drupal_add_js ('$(document).ready(function(){$("li.menu-1 a").click(function() {     window.open(this.href); return false; }    ); 
}

Setting Different Page Design for a Content Type

Setting Different Page Design for a Content Type:

If we want to create different page design for your content,then you need to create a content type and below that content you need to create the contents.Then if we need to create a tpl file for that content type.
For Example if you are creating a Content Type as "right",then you need to create a tpl like page-node-right.tpl.php.
After Creating the Content Type and tpl File,you should do this finally inside phptemplate_preprocess_page in your template file,

function phptemplate_preprocess_page(&$variables) {

    if ($variables['node']->type == "right") {
        $variables['template_files'][] = "page-node-" . $variables['node']->type;
    }

}

Setting Browser Title for Each Pages

Setting Browser Title for Each Pages: 

While Creating a page or node in a site,we should give the browser title,
for that we need to give this code inside the phptemplate_preprocess_page function in template.php.
for Example if your page is Contact Us and the url is contact_us,you need to write the code like this,

function phptemplate_preprocess_page(&$variables) {
   
    $path = drupal_get_path_alias($_GET['q']);
   
    if($path == 'contact_us'){
       $variables['head_title'] = 'Your Project Name - Contact Us';
     }

}